-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBasic_Page_with_Button.py
40 lines (33 loc) · 1.51 KB
/
Basic_Page_with_Button.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
#BPG is a class of tkinter
from breezypythongui import EasyFrame
class ButtonDemo(EasyFrame):
"""Illustrates command buttons and user events."""
def __init__(self):
"""Sets up the window, label, and buttons."""
EasyFrame.__init__(self)
# A single label in the first row.
self.label = self.addLabel(text = "Hello world!",
row = 0, column = 0,
columnspan = 2, sticky = "NSEW")
# Two command buttons in the second row.
self.clearBtn = self.addButton(text = "Clear",
row = 1, column = 0,
command = self.clear)
self.restoreBtn = self.addButton(text = "Restore",
row = 1, column = 1,
command = self.restore,
state = "disabled")
# Methods to handle user events.
def clear(self):
"""Resets the label to the empty string and the button states."""
self.label["text"] = ""
self.clearBtn["state"] = "disabled"
self.restoreBtn["state"] = "normal"
def restore(self):
"""Resets the label to 'Hello world!'and sets the state of the buttons."""
self.label["text"] = "Hello world!"
self.clearBtn["state"] = "normal"
self.restoreBtn["state"] = "disabled"
# Instantiates and pops up the window.
if __name__ == "__main__":
ButtonDemo().mainloop()