Python倒计时程序

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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"] = 50
        self.entryWidget.pack(side=LEFT)
        self.hi_there = Button(frame, text="开始", command=self.start)
        self.hi_there.pack(side=LEFT)
    def start(self):
        text = self.entryWidget.get().strip()
        root.attributes('-fullscreen', True)
        self.hi_there.pack_forget()
        self.entryWidget.pack_forget()
        self.countDown(int(text))

    def countDown(self,seconds):
        lbl1.config(bg='yellow')
        lbl1.config(height=3, font=('times', 200, '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='#000000')
        lbl1["text"] = ""
        tkinter.messagebox.showinfo("结束","结束")
        root.attributes('-fullscreen', F)
        root.quit()

        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()

def key(key):
    root.quit()

root = Tk()
root.title("")
lbl1 = Label()
lbl1.pack(fill=BOTH, expand=1)
app = App(root)
root.bind("<Escape>", key)
root.mainloop()