-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtkinter-countdown-stop.py
52 lines (41 loc) · 1.32 KB
/
tkinter-countdown-stop.py
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
"""A simple tkinter example
========================
Example use of **mainloop()** to create an event-driven program.
"""
from tkinter import Tk, Button
from time import sleep
class SimpleGUI:
def __init__(self, root: Tk):
"""Constructor for a simple tkinter GUI
:param root: The root tk application
:type root: Tk
"""
self.__root = root
self.__root.title("Countdown")
self.start_button = Button(self.__root, text="Start", command=self.start)
self.start_button.pack()
self.stop_button = Button(self.__root, text="Stop", command=self.stop)
self.stop_button.pack()
def start(self):
"""The start action. Performed when the start button is pressed.
"""
self.stop_countdown = False
for i in range(10, 0, -1):
print(i)
self.__root.update()
if self.stop_countdown:
break
sleep(1.0)
self.__root.update()
if not self.stop_countdown:
print("Go!")
def stop(self):
"""The stop action. Performed when the stop button is pressed.
"""
print("Stopping...")
self.stop_countdown = True
if __name__ == "__main__":
root = Tk()
my_gui = SimpleGUI(root)
root.mainloop()
print("Goodbye")