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í)功能。

- 使用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: 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()
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- python實(shí)現(xiàn)倒計(jì)時(shí)的示例
- python實(shí)現(xiàn)倒計(jì)時(shí)小工具
- python實(shí)現(xiàn)的簡(jiǎn)單窗口倒計(jì)時(shí)界面實(shí)例
- python 實(shí)現(xiàn)倒計(jì)時(shí)功能(gui界面)
- python實(shí)現(xiàn)七段數(shù)碼管和倒計(jì)時(shí)效果
- python使用tkinter實(shí)現(xiàn)屏幕中間倒計(jì)時(shí)
- python實(shí)現(xiàn)windows倒計(jì)時(shí)鎖屏功能
- 親手教你用Python打造一款摸魚倒計(jì)時(shí)界面
- python基于tkinter制作下班倒計(jì)時(shí)工具
- 基于Python實(shí)現(xiàn)倒計(jì)時(shí)工具
相關(guān)文章
Python中的數(shù)據(jù)對(duì)象持久化存儲(chǔ)模塊pickle的使用示例
這篇文章主要介紹了Python中的數(shù)據(jù)對(duì)象持久化存儲(chǔ)模塊pickle的使用示例,重點(diǎn)講解了pickle中模塊中對(duì)象持久化和文件讀取的相關(guān)方法,需要的朋友可以參考下2016-03-03
舉例簡(jiǎn)單講解Python中的數(shù)據(jù)存儲(chǔ)模塊shelve的用法
這篇文章主要介紹了舉例簡(jiǎn)單講解Python中的數(shù)據(jù)存儲(chǔ)模塊shelve的用法,shelveshelve模塊與pickle模塊的功能相近,比pickle用起來(lái)更為簡(jiǎn)單,需要的朋友可以參考下2016-03-03
詳解python異步編程之a(chǎn)syncio(百萬(wàn)并發(fā))
這篇文章主要介紹了詳解python異步編程之a(chǎn)syncio(百萬(wàn)并發(fā)),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-07-07
Python如何在ubuntu中更改Python和pip指向
這篇文章主要介紹了Python如何在ubuntu中更改Python和pip指向問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08
據(jù)Python爬蟲(chóng)不靠譜預(yù)測(cè)可知今年雙十一銷售額將超過(guò)6000億元
已經(jīng)是十一月十號(hào)了,雙十一即將到來(lái),電商早已預(yù)熱多日,為了在實(shí)戰(zhàn)中獲得能力的提升,本篇文章手把手帶你用Python來(lái)預(yù)測(cè)一下今年雙十一的銷售額將會(huì)達(dá)到多少,大家可以在過(guò)程中查缺補(bǔ)漏,提升水平2021-11-11
python中使用mysql數(shù)據(jù)庫(kù)詳細(xì)介紹
這篇文章主要介紹了python中使用mysql數(shù)據(jù)庫(kù)詳細(xì)介紹,本文起講解了安裝mysql、安裝MySQL-python、mysql 的基本操作、python 操作mysql數(shù)據(jù)庫(kù)基礎(chǔ)等內(nèi)容,需要的朋友可以參考下2015-03-03
基于python實(shí)現(xiàn)可視化生成二維碼工具
這篇文章主要介紹了基于python實(shí)現(xiàn)可視化生成二維碼工具,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-07-07
Python中生成一個(gè)指定長(zhǎng)度的隨機(jī)字符串實(shí)現(xiàn)示例
這篇文章主要介紹了Python中生成一個(gè)指定長(zhǎng)度的隨機(jī)字符串,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11

