-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcheckboxes.py
61 lines (43 loc) · 1.3 KB
/
checkboxes.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from tkinter import *
root = Tk()
root.title("CheckButtons - Intro To Tkinter")
root.iconbitmap('images/tkinter.ico')
root.geometry('600x400')
def clicked():
# Check for pepperoni
if var1.get() == 1:
pepperoni = "Pepperoni"
else:
pepperoni = ""
# Check for cheese
if var2.get() == 1:
cheese = "Cheese"
else:
cheese = ""
# Check for mushroom
if var3.get() == 1:
mushroom = "Mushroom"
else:
mushroom = ""
if pepperoni or cheese or mushroom:
my_label.config(text=f"You Selected {pepperoni} {cheese} {mushroom}")
else:
my_label.config(text="You Didn't Pick Anything!")
# Create some IntVars()
var1 = IntVar()
var2 = IntVar()
var3 = IntVar()
# Create 3 checkboxes
check1 = Checkbutton(root, text="Pepperoni", variable=var1, onvalue=1, offvalue=0, font=("Helvetica", 18))
check1.pack(pady=(40, 10))
check2 = Checkbutton(root, text="Cheese", variable=var2, onvalue=1, offvalue=0, font=("Helvetica", 18))
check2.pack(pady=(40, 10))
check3 = Checkbutton(root, text="Mushroom", variable=var3, onvalue=1, offvalue=0, font=("Helvetica", 18))
check3.pack(pady=(40, 10))
# Create a button
my_button = Button(root, text="Submit", command=clicked)
my_button.pack(pady=20)
# Create a label
my_label = Label(root, text="Pick A Topping", font=("Helvetica", 18))
my_label.pack(pady=20)
root.mainloop()