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

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

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

使用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í)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

左贡县| 承德市| 贵港市| 千阳县| 南宁市| 来凤县| 榕江县| 仙桃市| 莎车县| 手游| 蒙城县| 项城市| 炉霍县| 湘潭市| 巢湖市| 屏东市| 奉新县| 洪泽县| 巧家县| 宁蒗| 高雄县| 黔江区| 钦州市| 凉山| 丹巴县| 海原县| 临猗县| 上高县| 古丈县| 大姚县| 吉隆县| 永泰县| 竹溪县| 柳州市| 洛阳市| 黄浦区| 昔阳县| 兰西县| 漾濞| 罗田县| 枝江市|