python實(shí)現(xiàn)簡(jiǎn)單倒計(jì)時(shí)功能
使用python實(shí)現(xiàn)簡(jiǎn)單倒計(jì)時(shí)exe,供大家參考,具體內(nèi)容如下
使用tkinter制作界面實(shí)現(xiàn)倒計(jì)時(shí)功能。
代碼如下:
#!/usr/bin/python3.8# -*- coding: utf-8 -*-# @Time : 2021/4/19 14:09# @Author : dongdong# @File : CountdownGUI.py# @Software: PyCharmfrom tkinter import *import timeimport threadingdef cyclethread(): global counttime global restartflag global runflag restartflag=False if (timestr.get().isdigit()):counttime = int(timestr.get()) * 60 else:runflag=Falsereturn; while (1):if(restartflag): counttime = int(timestr.get()) * 60 restartflag=Falseif(exitflag): sys.exit()counttime=counttime-1v=’nleft time:’+str(counttime//60)+’ :’+str(counttime%60)textshow.set(v)root.update()if (counttime <= 0): runflag = False returntime.sleep(1)def startCount(): global restartflag global runflag restartflag=True if( not runflag):th=threading.Thread(target=cyclethread)th.setDaemon(True)th.start()runflag = Truedef exitfun(): global exitflag exitflag=True sys.exit()restartflag=Falseexitflag=Falsecounttime=Nonerunflag=Falseroot=Tk()root.geometry(’250x120’)root.title(’TimeCounter’)timestr = StringVar(value='30')textshow=StringVar(value=’nCountDown:30min ’)text0=Label(root,text=’Input time(min):’).grid(row=0,column=0,columnspan=3)entext=Entry(root,textvariable=timestr).grid(row=0,column=3,columnspan=1)# bnframe=ttk.Frame(root).grid(row=1,column=0,columnspan=4)stbn=Button(root,text=’Start’,command=startCount).grid(row=1,column=2,columnspan=1)enbn=Button(root,text=’Exit’,command=exitfun).grid(row=1,column=3,columnspan=1)text=Label(root,textvariable=textshow).grid(row=2,column=0,columnspan=4)root.mainloop()
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. .NET 中配置從xml轉(zhuǎn)向json方法示例詳解2. ASP錯(cuò)誤捕獲的幾種常規(guī)處理方式3. Laravel中數(shù)據(jù)庫(kù)遷移操作的示例詳解4. 得到XML文檔大小的方法5. asp錯(cuò)誤 '80040e21' 多步 OLE DB 操作產(chǎn)生錯(cuò)誤6. Python 如何將字符串每?jī)蓚€(gè)用空格隔開(kāi)7. 詳解php如何合并身份證正反面圖片為一張圖片8. ASP編碼必備的8條原則9. asp.net core項(xiàng)目授權(quán)流程詳解10. 詳解JS前端使用迭代器和生成器原理及示例
