I'm studying GUI for Python, and I don't know how to disable a button with a check button. Which trigger does Python use to verify if I mark the check button? Follow some code I wrote trying to do it, but without success.
Sorry for my bad English.
from tkinter import *
from tkinter import ttk
class HelloApp:
def __init__(self, master):
self.label = ttk.Label(master, text="Hello, Tkinter!")
self.button1 = ttk.Button(master, text="Texas", command=self.texas_hello)
self.button2 = ttk.Button(master, text="Hawaii", command=self.hawaii_hello)
value_check = IntVar()
def disable_button(button):
button.config(state=DISABLED)
def enable_button(button):
button.config(state=NORMAL)
checkbutton = ttk.Checkbutton(master, variable=value_check, text='Deactivate!',
onvalue=enable_button(self.button1),
offvalue=disable_button(self.button1))
self.label.grid(row=0, column=0, columnspan=2)
self.button1.grid(row=1, column=0)
self.button2.grid(row=1, column=1)
checkbutton.grid(row=1, column=2)
print(value_check)
def texas_hello(self):
self.label.config(text='Howdy, Tkinter!')
def hawaii_hello(self):
self.label.config(text='Aloha, Tkinter!')
def main():
root = Tk()
HelloApp(root)
root.mainloop()
if __name__ == "main": main()
main()