這篇文章給大家分享的是有關(guān)使用Python實(shí)現(xiàn)秒表功能的方法的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個參考。一起跟隨小編過來看看吧。
創(chuàng)新互聯(lián)建站專注于隆子網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供隆子營銷型網(wǎng)站建設(shè),隆子網(wǎng)站制作、隆子網(wǎng)頁設(shè)計(jì)、隆子網(wǎng)站官網(wǎng)定制、小程序開發(fā)服務(wù),打造隆子網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供隆子網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。創(chuàng)新互聯(lián)公司專注于托里網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供托里營銷型網(wǎng)站建設(shè),托里網(wǎng)站制作、托里網(wǎng)頁設(shè)計(jì)、托里網(wǎng)站官網(wǎng)定制、成都微信小程序服務(wù),打造托里網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供托里網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。創(chuàng)新互聯(lián)專注于旬陽網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供旬陽營銷型網(wǎng)站建設(shè),旬陽網(wǎng)站制作、旬陽網(wǎng)頁設(shè)計(jì)、旬陽網(wǎng)站官網(wǎng)定制、微信小程序服務(wù),打造旬陽網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供旬陽網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。關(guān)于Tkinter:
Tkinter是Python的標(biāo)準(zhǔn)GUI庫。Python與Tkinter結(jié)合使用時(shí),提供了一種創(chuàng)建GUI應(yīng)用程序的快速而簡單的方法。Tkinter為Tk GUI工具包提供了一個強(qiáng)大的面向?qū)ο蠼涌凇kinter很容易入門,下面是一些示例代碼,可以讓您在python中使用Tkinter。
語法:
# Python program to create a # a new window using Tkinter # importing the required libraires import tkinter # creating a object 'top' as instance of class Tk top = tkinter.Tk() # This will start the blank window top.mainloop()
輸出:
使用Tkinter創(chuàng)建秒表
現(xiàn)在讓我們嘗試使用Tkinter模塊創(chuàng)建一個程序來創(chuàng)建秒表。
所需模塊:我們將僅使用tkinter來創(chuàng)建gui,并且此程序中將不使用其他任何庫。
# Python program to illustrate a stop watch # using Tkinter #importing the required libraries import tkinter as Tkinter counter = -1 running = False def counter_label(label): def count(): if running: global counter # To manage the intial delay. if counter==-1: display="Starting..." else: display=str(counter) label['text']=display # Or label.config(text=display) # label.after(arg1, arg2) delays by # first argument given in milliseconds # and then calls the function given as second argument. # Generally like here we need to call the # function in which it is present repeatedly. # Delays by 1000ms=1 seconds and call count again. label.after(1000, count) counter += 1 # Triggering the start of the counter. count() # start function of the stopwatch def Start(label): global running running=True counter_label(label) start['state']='disabled' stop['state']='normal' reset['state']='normal' # Stop function of the stopwatch def Stop(): global running start['state']='normal' stop['state']='disabled' reset['state']='normal' running = False # Reset function of the stopwatch def Reset(label): global counter counter=-1 # If rest is pressed after pressing stop. if running==False: reset['state']='disabled' label['text']='Welcome!' # If reset is pressed while the stopwatch is running. else: label['text']='Starting...' root = Tkinter.Tk() root.title("Stopwatch") # Fixing the window size. root.minsize(width=250, height=70) label = Tkinter.Label(root, text="Welcome!", fg="black", font="Verdana 30 bold") label.pack() start = Tkinter.Button(root, text='Start', width=15, command=lambda:Start(label)) stop = Tkinter.Button(root, text='Stop', width=15, state='disabled', command=Stop) reset = Tkinter.Button(root, text='Reset', width=15, state='disabled', command=lambda:Reset(label)) start.pack() stop.pack() reset.pack() root.mainloop()
輸出:
感謝各位的閱讀!關(guān)于使用Python實(shí)現(xiàn)秒表功能的方法就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
網(wǎng)站標(biāo)題:使用Python實(shí)現(xiàn)秒表功能的方法-創(chuàng)新互聯(lián)
文章地址:http://www.rwnh.cn/article22/cehscc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、Google、定制網(wǎng)站、動態(tài)網(wǎng)站、網(wǎng)站維護(hù)、網(wǎng)站改版
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)