Skip to content

Instantly share code, notes, and snippets.

@vigilantPotato
Created March 14, 2024 21:52
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/1e5722cda388cab7dea2ada3c3913f02 to your computer and use it in GitHub Desktop.
Save vigilantPotato/1e5722cda388cab7dea2ada3c3913f02 to your computer and use it in GitHub Desktop.
How to change widget's state with checkbutton
import ctypes
import tkinter
#Function when checkbutton clicked
def change_button_state():
if var.get():
b["state"] = "disable" #disable
else:
b["state"] = "active" #activate
if __name__ == "__main__":
ctypes.windll.shcore.SetProcessDpiAwareness(1)
root = tkinter.Tk()
b = tkinter.Button(
root,
text="button",
width=15,
)
b.pack()
var = tkinter.BooleanVar(root)
check = tkinter.Checkbutton(
root,
text="disable button",
variable=var, #set variable
command=change_button_state,
)
check.pack()
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment