-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtkinter_practice.py
More file actions
81 lines (68 loc) · 2.35 KB
/
tkinter_practice.py
File metadata and controls
81 lines (68 loc) · 2.35 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import tkinter as tk
import tkinter.messagebox as msg
class MyGUI:
def __init__(self):
self.main_window = tk.Tk()
self.main_window.title("Main Window")
# (border style): relief='' flat, raised, sunken, solid, ridge, groove
# (side): side='' top, bottom, left, right
# (fill): fill='' x, y, both, none
# (expand): expand=True, False
# (external padding): padx=, pady=
# (anchor): anchor='' n, ne, e, se, s, sw, w, nw, center
# (internal padding): ipadx=, ipady=
# (stretch): stretch=True, False
# (weight): weight=0, 1, 2, 3, 4, 5
# (minsize): minsize=0, 1, 2, 3, 4, 5
# self.label = tk.Label(
# self.main_window,
# text="Hello World!",
# bg="red",
# fg="white",
# relief="raised",
# borderwidth=5,
# padx=10,
# pady=10,
# anchor="center",
# width=20,
# height=5
# )
# self.label2 = tk.Label(
# self.main_window,
# text="Goodbye World!",
# bg="blue",
# fg="white",
# relief="raised",
# borderwidth=5,
# padx=10,
# pady=10,
# anchor="center",
# width=20,
# height=5
# )
# frame= creates a frame widget
self.top_frame = tk.Frame(self.main_window)
self.bottom_frame = tk.Frame(self.main_window)
# button= creates a button widget
# command= is used to call a function when the button is clicked
self.my_button = tk.Button(
self.main_window, text="Click Me!", command=self.do_something
)
self.quit_button = tk.Button(
self.main_window, text="Quit", command=self.main_window.destroy
)
# pack() places the widget in the first available position
# self.label.pack(side="left")
# self.label2.pack(side="left")
self.my_button.pack()
self.quit_button.pack()
self.top_frame.pack()
self.bottom_frame.pack()
# mainloop() keeps the window open until the user closes it
tk.mainloop()
def do_something(self):
msg.showinfo("Response", "Thanks for clicking the button!")
def main():
MyGUI()
if __name__ == "__main__":
main()