如何用Python写一个简易的倒计时exe
Admin 2022-07-20 群英技术资讯 753 次浏览
使用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中opencv K均值聚类的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧<BR>
在日常工作编程中存在着各种随机事件,同样在编程中生成随机数字的时候也是一样,随机有多随机呢?在涉及信息安全的情况下,它是最重要的问题之一。每当在 Python 中生成随机数据、字符串或数字时,最好至少大致了解这些数据是如何生成的。用于在 Python 中生成随机数据的不同选项,然后在安全性、多功能性、用途和速度方面对每个选项进行比较。本篇内容不是数学或密码学相关内容,仅仅是根据需要进行尽可能多的数学运算仅此而已。
这篇文章主要介绍了Python类的定义与使用,类名只要是一个合法的标识符即可,但这仅仅满足的是 Python 的语法要求:如果从程序的可读性方面来看,Python 的类名必须是由一个或多个有意义的单词连缀而成的,下文基于这些基础内容展开介绍,需要的朋友可以参考一下
怎样用python写一个截屏工具?对于截屏工具的应用场景有很多,我们经常可以使用到,截屏工具也是比较实用的,下面我们就来看看用Python怎样实现截屏工具。感兴趣的朋友可以参考看看。
pytorch Visdom可视化,是一个灵活的工具,用于创建,组织和共享实时丰富数据的可视化。这篇文章我们就来了解pytorch visdom怎样安装,以及visdom的用法,感兴趣的接下来就跟随小编来了解看看吧!
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008