Skip to content

Instantly share code, notes, and snippets.

@vigilantPotato
Created March 18, 2024 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vigilantPotato/5ed3fdd9df7eaa0ee657a331cb078b3c to your computer and use it in GitHub Desktop.
Save vigilantPotato/5ed3fdd9df7eaa0ee657a331cb078b3c to your computer and use it in GitHub Desktop.
How to obtain which checkbutton is selected
import ctypes
import tkinter
if __name__ == "__main__":
ctypes.windll.shcore.SetProcessDpiAwareness(1)
root = tkinter.Tk()
#variable
var = tkinter.IntVar(root)
#display selected checkbutton No.
label = tkinter.Label(root, textvariable=var)
label.pack()
#No.1 checkbutton
check1 = tkinter.Checkbutton(
root,
text="check_1",
variable=var,
onvalue=1,
)
check1.pack()
#No.2 checkbutton
check2 = tkinter.Checkbutton(
root,
text="check_2",
variable=var,
onvalue=2,
)
check2.pack()
#No.3 checkbutton
check3 = tkinter.Checkbutton(
root,
text="check_3",
variable=var,
onvalue=3,
)
check3.pack()
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment