- Checkbox
- BooleanVar
Python Tk Checkbox
examples/tk/tk_checkbox.py
import tkinter as tk app = tk.Tk() app.title('Checkbox') var1 = tk.BooleanVar() cb1 = tk.Checkbutton(app, text='male', variable=var1) cb1.pack() var2 = tk.BooleanVar() cb2 = tk.Checkbutton(app, text='female', variable=var2) cb2.pack() #var1.set(True) def clicked(): print(var1.get()) print(var2.get()) #print(dir(cb1)) button = tk.Button(app, text='Show', width=25, command=clicked) button.pack() exit_button = tk.Button(app, text='Close', width=25, command=app.destroy) exit_button.pack() app.mainloop()