-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapplication.py
More file actions
50 lines (40 loc) · 1.62 KB
/
application.py
File metadata and controls
50 lines (40 loc) · 1.62 KB
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
import tkinter as tk
BUTTON_START_NAME = "Start"
BUTTON_PAUSE_NAME = "Pause"
BUTTON_RESET_NAME = "Reset"
BUTTON_ENABLED = "normal"
BUTTON_DISABLED = "disabled"
BUTTON_WIDTH = 10
BUTTON_FONT = ("Arial", 16)
LABEL_FONT = ("Helvetica", 32)
class Application(tk.Frame):
def __init__(self, tkinter, view):
super().__init__(tkinter)
self.tkinter = tkinter
self.view = view
self.tkinter.title("TKimer")
self.tkinter.protocol("WM_DELETE_WINDOW", self.view.handle_quit)
self.pack()
self.create_widgets()
def create_widgets(self):
self.lbl_time = tk.Label(self, text="", font=LABEL_FONT)
self.lbl_time.pack(side="bottom")
self.btn_start = tk.Button(self)
self.btn_start["text"] = BUTTON_START_NAME
self.btn_start["font"] = BUTTON_FONT
self.btn_start["width"] = BUTTON_WIDTH
self.btn_start["command"] = self.view.handle_start
self.btn_start.pack(side="left")
self.btn_reset = tk.Button(self)
self.btn_reset["text"] = BUTTON_RESET_NAME
self.btn_reset["font"] = BUTTON_FONT
self.btn_reset["width"] = BUTTON_WIDTH
self.btn_reset["command"] = self.view.handle_reset
self.btn_reset.pack(side="left")
self.btn_reset["state"] = BUTTON_DISABLED
def update_widgets(self, time_string, is_running, is_idle):
start_name = BUTTON_PAUSE_NAME if is_running else BUTTON_START_NAME
reset_state = BUTTON_DISABLED if is_idle else BUTTON_ENABLED
self.lbl_time["text"] = time_string
self.btn_start["text"] = start_name
self.btn_reset["state"] = reset_state