最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python實現(xiàn)簡單倒計時功能

 更新時間:2021年04月20日 17:17:10   作者:一條小白魚  
這篇文章主要為大家詳細介紹了python實現(xiàn)簡單倒計時功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

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

  • 使用time.sleep(1)實現(xiàn) 秒級 倒計時
  • 使用線程避免界面卡死
  • 在線程的循環(huán)中檢測全局標志位,保證計時線程的重置、以及退出
  • 使用pyinstaller -F file.py -w 生成exe文件,-w表示隱藏控制臺,-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()

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

建昌县| 江阴市| 新安县| 海门市| 平阴县| 莆田市| 宁河县| 朔州市| 阿勒泰市| 历史| 额尔古纳市| 泸西县| 专栏| 天柱县| 得荣县| 安塞县| 晋宁县| 沈丘县| 新建县| 南通市| 美姑县| 黑龙江省| 措勤县| 崇义县| 湄潭县| 石台县| 博湖县| 淄博市| 浪卡子县| 连云港市| 哈巴河县| 赫章县| 定边县| 桐乡市| 内乡县| 额济纳旗| 郴州市| 巨鹿县| 大庆市| 霍山县| 尼玛县|