久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

python實(shí)現(xiàn)簡單倒計(jì)時(shí)功能

瀏覽:3日期:2022-06-21 18:18:35

使用python實(shí)現(xiàn)簡單倒計(jì)時(shí)exe,供大家參考,具體內(nèi)容如下

使用tkinter制作界面實(shí)現(xiàn)倒計(jì)時(shí)功能。

python實(shí)現(xiàn)簡單倒計(jì)時(shí)功能

使用time.sleep(1)實(shí)現(xiàn) 秒級(jí) 倒計(jì)時(shí) 使用線程避免界面卡死 在線程的循環(huán)中檢測(cè)全局標(biāo)志位,保證計(jì)時(shí)線程的重置、以及退出 使用pyinstaller -F file.py -w 生成exe文件,-w表示隱藏控制臺(tái),-F表示生成單文件

代碼如下:

#!/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()

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 贡山| 广宁县| 礼泉县| 襄垣县| 山丹县| 蛟河市| 丰顺县| 灵宝市| 娄底市| 福泉市| 丘北县| 长顺县| 常山县| 谷城县| 青浦区| 常熟市| 桂阳县| 桐庐县| 龙陵县| 蒲江县| 乌兰浩特市| 利津县| 油尖旺区| 荆门市| 织金县| 佳木斯市| 兴文县| 弥渡县| 平山县| 土默特右旗| 多伦县| 忻州市| 朔州市| 营山县| 拜城县| 四川省| 黑河市| 黑山县| 巴中市| 高碑店市| 武安市|