如何用Python写一个简易的倒计时exe
Admin 2022-07-20 群英技术资讯 995 次浏览
使用tkinter制作界面实现倒计时功能。
代码如下:
#!/usr/bin/python3.8 # -*- coding: utf-8 -*- # @Time : 2021/4/19 14:09 # @Author : dongdong # @File : CountdownGUI.py # @Software: PyCharm from tkinter import * import time import threading def cyclethread(): global counttime global restartflag global runflag restartflag=False if (timestr.get().isdigit()): counttime = int(timestr.get()) * 60 else: runflag=False return; while (1): if(restartflag): counttime = int(timestr.get()) * 60 restartflag=False if(exitflag): sys.exit() counttime=counttime-1 v='\nleft time:'+str(counttime//60)+' :'+str(counttime%60) textshow.set(v) root.update() if (counttime <= 0): runflag = False return time.sleep(1) def startCount(): global restartflag global runflag restartflag=True if( not runflag): th=threading.Thread(target=cyclethread) th.setDaemon(True) th.start() runflag = True def exitfun(): global exitflag exitflag=True sys.exit() restartflag=False exitflag=False counttime=None runflag=False root=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()
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
最近在使用python做接口测试,发现python中http请求方法有许多种,今天抽点时间把相关内容整理,分享给大家,具体内容如下所示:一、python
Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块,下面这篇文章主要给大家介绍了关于Python中条件语句、循环语句和pass语句使用的相关资料,需要的朋友可以参考下
这篇文章主要为大家介绍了python目标检测yolo1 yolo2 yolo3和SSD网络结构对比,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
python的input函数怎样用?input函数是python中比较实用的一个函数,对此,这篇文章就主要给大家分享input函数的使用,具有一定的借鉴价值,感兴趣的朋友可以参考一下,希望大家阅读完这篇文章能有所收获,下面我们一起来学习一下。
Python语言允许在定义函数的时候,其函数体内又包含另外一个函数的完整定义,这就是我们通常所说的嵌套定义。实例1:defOutFun(): 定义函数
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008