Skip to content

Commit 21a1199

Browse files
committedApr 24, 2018
Code files
Tkinter GUI Programming by Example, published by Packt
1 parent 3d6bba8 commit 21a1199

File tree

145 files changed

+6234
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+6234
-0
lines changed
 

Diff for: ‎Chapter01/Ch1/ch1-1.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import tkinter as tk
2+
3+
class Window(tk.Tk):
4+
def __init__(self):
5+
super().__init__()
6+
self.title("Hello Tkinter")
7+
8+
label = tk.Label(self, text="Hello World!")
9+
label.pack(fill=tk.BOTH, expand=1, padx=100, pady=50)
10+
11+
12+
if __name__ == "__main__":
13+
window = Window()
14+
window.mainloop()
15+

Diff for: ‎Chapter01/Ch1/ch1-2.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import tkinter as tk
2+
3+
class Window(tk.Tk):
4+
def __init__(self):
5+
super().__init__()
6+
self.title("Hello Tkinter")
7+
8+
self.label = tk.Label(self, text="Choose One")
9+
self.label.pack(fill=tk.BOTH, expand=1, padx=100, pady=30)
10+
11+
hello_button = tk.Button(self, text="Say Hello", command=self.say_hello)
12+
hello_button.pack(side=tk.LEFT, padx=(20, 0), pady=(0, 20))
13+
14+
goodbye_button = tk.Button(self, text="Say Goodbye", command=self.say_goodbye)
15+
goodbye_button.pack(side=tk.RIGHT, padx=(0, 20), pady=(0, 20))
16+
17+
def say_hello(self):
18+
self.label.configure(text="Hello World!")
19+
20+
def say_goodbye(self):
21+
self.label.configure(text="Goodbye! \n (Closing in 2 seconds)")
22+
self.after(2000, self.destroy)
23+
24+
25+
if __name__ == "__main__":
26+
window = Window()
27+
window.mainloop()
28+

0 commit comments

Comments
 (0)