16. Tkinter: Checkboxes

Опубликовано: 07 Октябрь 2024
на канале: Game Design with Reilly
408
5

Video code

from tkinter import *

def submit():
if result1.get() == 1:
print("Python is great")
if result2.get() == 1:
print("C++ is great")
if result1.get() == 0 and result2.get() == 0:
print("You do not like either option")


window = Tk()
window.title("My program")
window.geometry("350x200")

result1 = IntVar()
result2 = IntVar()

c1 = Checkbutton(window, text="Python", variable=result1, onvalue=1, offvalue=0)
c1.pack()
c2 = Checkbutton(window, text="C++", variable=result2, onvalue=1, offvalue=0)
c2.pack()

button = Button(window, text="Submit", command=submit)
button.pack(side=BOTTOM, fill =Y,)

window.mainloop()