python實(shí)現(xiàn)倒計(jì)時(shí)小工具
本文實(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("開(kāi)始計(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("開(kāi)始計(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="開(kāi)始", 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()
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 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)簡(jiǎ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打造一款摸魚(yú)倒計(jì)時(shí)界面
- python基于tkinter制作下班倒計(jì)時(shí)工具
- 基于Python實(shí)現(xiàn)倒計(jì)時(shí)工具
相關(guān)文章
Python實(shí)現(xiàn)類(lèi)的創(chuàng)建與使用方法示例
這篇文章主要介紹了Python實(shí)現(xiàn)類(lèi)的創(chuàng)建與使用方法,結(jié)合簡(jiǎn)單計(jì)算器功能實(shí)例分析了Python類(lèi)的定義與使用方法,需要的朋友可以參考下2017-07-07使用Python第三方庫(kù)xlrd讀取Excel中的數(shù)據(jù)的流程步驟
這篇文章主要給大家介紹了使用Python第三方庫(kù)xlrd讀取Excel中的數(shù)據(jù)的流程步驟,文中通過(guò)代碼示例給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2023-12-12詳解Python3 定義一個(gè)跨越多行的字符串的多種方法
這篇文章主要介紹了詳解Python3 定義一個(gè)跨越多行的字符串的多種方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09Python使用列表和字典實(shí)現(xiàn)簡(jiǎn)單的考試系統(tǒng)詳解
這篇文章主要介紹了Python使用列表和字典實(shí)現(xiàn)簡(jiǎn)單的考試系統(tǒng),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2023-01-01scikit-learn線性回歸,多元回歸,多項(xiàng)式回歸的實(shí)現(xiàn)
這篇文章主要介紹了scikit-learn線性回歸,多元回歸,多項(xiàng)式回歸的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08解讀python正則表達(dá)式括號(hào)問(wèn)題
這篇文章主要介紹了python正則表達(dá)式括號(hào)問(wèn)題解讀,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09Python面向?qū)ο缶幊袒A(chǔ)實(shí)例分析
這篇文章主要介紹了Python面向?qū)ο缶幊袒A(chǔ),結(jié)合實(shí)例形式分析了Python面向?qū)ο缶幊填?lèi)的定義、繼承、特殊方法及模塊相關(guān)原理與操作技巧,需要的朋友可以參考下2020-01-01