python實(shí)現(xiàn)倒計(jì)時(shí)小工具
更新時(shí)間:2019年07月29日 15:50:34 作者:俠之大者為國為民
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)倒計(jì)時(shí)小工具,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了python實(shí)現(xiàn)倒計(jì)時(shí)小工具的具體代碼,供大家參考,具體內(nèi)容如下
#!/usr/bin/env python
# coding=utf-8
import threading
import time
import Queue
from Tkinter import *
import tkMessageBox
import logging
logging.basicConfig(level=logging.INFO)
## Communication queue
commQueue = Queue.Queue()
g_time = 0
## Function run in thread
def timeThread():
global g_time
g_time = timeVar.get() * 60
while 1:
logging.info("線程放入隊(duì)列:%d".decode("utf-8") % g_time)
commQueue.put(g_time)
try:
root.event_generate('<<TimeChanged>>', when='tail')
except TclError:
break
time.sleep(1)
g_time -= 1
if g_time==-1:
begin_btn["fg"] = "black"
clockVar.set("開始計(jì)時(shí)")
break
def timeChanged(event):
x = commQueue.get()
logging.info("獲取隊(duì)列:%d".decode("utf-8") % x)
minits = x//60
seconds = x%60
s = "剩余時(shí)間 {:02}:{:02}".format(minits, seconds)
begin_btn["fg"] = "blue"
clockVar.set(s)
if x==0:
tkMessageBox.showinfo("提醒","時(shí)間已到")
def clock_func(*args):
global g_time
if threading.activeCount()>1:
g_time = timeVar.get() * 60
else:
th=threading.Thread(target=timeThread)
th.start()
## Create main window
root = Tk()
root.title("計(jì)時(shí)工具")
root.geometry("180x95-0-45")
root.resizable(width=FALSE,height=FALSE)
root.wm_attributes("-topmost",1)
frame = Frame(root)
frame.pack()
Label(frame,text="設(shè)定時(shí)間間隔").grid(row=1,column=2)
timeVar = IntVar()
clockVar = StringVar()
time_entry = Entry(frame, textvariable=timeVar, width=8)
time_entry["justify"] = "center"
time_entry.grid(row=2,column=2,sticky="W,E")
begin_btn = Button(frame,textvariable=clockVar,command=clock_func)
begin_btn.grid(row=3,column=2)
timeVar.set(8)
begin_btn["fg"] = "black"
clockVar.set("開始計(jì)時(shí)")
for child in frame.winfo_children():
child.grid_configure(pady=3)
time_entry.focus()
root.bind('<<TimeChanged>>', timeChanged)
root.bind("<Return>",clock_func)
root.mainloop()
小編再為大家分享一段代碼:Python窗口倒計(jì)時(shí)
# Countdown using Tkinter
from tkinter import *
import time
import tkinter.messagebox
class App:
def __init__(self,master):
frame = Frame(master)
frame.pack()
self.entryWidget = Entry(frame)
self.entryWidget["width"] = 15
self.entryWidget.pack(side=LEFT)
self.hi_there = Button(frame, text="開始", command=self.start)
self.hi_there.pack(side=LEFT)
self.button = Button(frame, text="退出", fg="red", command=frame.quit)
self.button.pack(side=LEFT)
def start(self):
text = self.entryWidget.get().strip()
if text != "":
num = int(text)
self.countDown(num)
def countDown(self,seconds):
lbl1.config(bg='yellow')
lbl1.config(height=3, font=('times', 20, 'bold'))
for k in range(seconds, 0, -1):
if k == 30:
print("\a")
if k== 29:
print("\a")
if k== 28:
print("\a")
lbl1["text"] = k
root.update()
time.sleep(1)
lbl1.config(bg='red')
lbl1.config(fg='white')
lbl1["text"] = "時(shí)間到!"
tkMessageBox.showinfo("時(shí)間到!","時(shí)間到!")
def GetSource():
get_window = Tkinter.Toplevel(root)
get_window.title('Source File?')
Tkinter.Entry(get_window, width=30,
textvariable=source).pack()
Tkinter.Button(get_window, text="Change",
command=lambda: update_specs()).pack()
root = Tk()
root.title("Countdown")
lbl1 = Label()
lbl1.pack(fill=BOTH, expand=1)
app = App(root)
root.mainloop()
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- python實(shí)現(xiàn)倒計(jì)時(shí)的示例
- python實(shí)現(xiàn)的簡單窗口倒計(jì)時(shí)界面實(shí)例
- python 實(shí)現(xiàn)倒計(jì)時(shí)功能(gui界面)
- python實(shí)現(xiàn)簡單倒計(jì)時(shí)功能
- 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編程語言入門黑客攻防 給你幾個(gè)理由!
為什么選擇python編程語言入門黑客攻防,小編今天給你幾個(gè)理由!Python語言的優(yōu)點(diǎn)、Python黑客攻擊優(yōu)點(diǎn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-02-02
PyTorch?模型?onnx?文件導(dǎo)出及調(diào)用詳情
這篇文章主要介紹了PyTorch模型onnx文件導(dǎo)出及調(diào)用詳情,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-07-07
matplotlib圖例legend語法及設(shè)置的方法
這篇文章主要介紹了matplotlib圖例legend語法及設(shè)置的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
python opencv 圖像處理之圖像算數(shù)運(yùn)算及修改顏色空間
這篇文章主要介紹了python opencv 圖像處理之圖像算數(shù)運(yùn)算及修改顏色空間,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友可以參考一下2022-08-08
Pytorch訓(xùn)練模型得到輸出后計(jì)算F1-Score 和AUC的操作
這篇文章主要介紹了Pytorch訓(xùn)練模型得到輸出后計(jì)算F1-Score 和AUC的操作,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-05-05

