Tkinter Checkbutton 勾选项
import tkinter as tk
window = tk.Tk()
window.title('my window')
window.geometry('600x400')
l = tk.Label(window, bg='yellow', width=100, text='empty')
l.pack()
def print_selection():
if var1.get() and var2.get():
l.config(text='i love both')
elif var1.get() or var2.get():
text = 'Python' if var1.get() else 'C++'
l.config(text='i love ' + text)
else:
l.config(text='i don\'t like either')
var1 = tk.IntVar()
var2 = tk.IntVar()
c1 = tk.Checkbutton(window,text='Python',variable=var1,onvalue=1,offvalue=0,
command=print_selection)
c2 = tk.Checkbutton(window,text='C++',variable=var2,onvalue=1,offvalue=0,
command=print_selection)
c1.pack()
c2.pack()
window.mainloop()