-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWidgets.py
43 lines (33 loc) · 991 Bytes
/
Widgets.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
import tkinter as tk
from tkinter import ttk
def button_func():
print("A button was pressed")
def hello_btn():
print("Hello!")
# Create a window
window = tk.Tk()
window.title('Window and Widgets')
window.geometry('800x500')
# ttk Widgets - Label
label = ttk.Label(master = window, text = 'This is a test')
label.pack()
# Create Widgets
# tk Text
text = tk.Text(master = window)
text.pack()
# ttk Entry
entry = ttk.Entry(master = window)
entry.pack()
# Exercise Label
exe_label = ttk.Label(master = window, text = 'My Label')
exe_label.pack()
# ttk Button
btn = ttk.Button(master = window, text = 'A button', command = button_func)
btn.pack()
# Exercise Button
# exe_btn = ttk.Button(master=window, text = 'Press to say hello', command = hello_btn)
exe_btn = ttk.Button(master=window, text = 'Press to say hello', command = lambda:print("Lambda btn - Hello!")) # Can also use lambda func (One use funcs)
exe_btn.pack()
# Run
window.mainloop()
print("Closed mainloop window")