You need to do two things:
Make a function to change the state of the entrybox that will be called each time the checkbutton is clicked. It should look something like this:
def switch(self): if self.CheckVar_theta.get(): self.entry11.config(state=DISABLED) else: self.entry11.config(state=NORMAL)
Assign the checkbutton's
command
parameter to that function:self.check = Checkbutton(self, ..., command=self.switch)
In the end, your code will look like this:
from Tkinter import *
import tkMessageBox
class MainWindow(Frame):
def __init__(self):
Frame.__init__(self)
self.master.title("input")
self.master.minsize(150, 50)
self.grid(sticky=E+W+N+S)
top=self.winfo_toplevel()
top.rowconfigure(0, weight=1)
top.columnconfigure(0, weight=1)
for i in range(1):self.rowconfigure(i, weight=1)
self.columnconfigure(1, weight=1)
self.label0 = Label(self, text="Data: ")
self.label0.grid(row=0, column=0, padx=2)
self.entry11 = Entry(self)
self.entry11.grid(row=0, column=1, pady=2, padx=2, sticky=E+W+N+S)
self.CheckVar_theta = IntVar()
self.check = Checkbutton(self, text="", variable=self.CheckVar_theta,
onvalue = 0, offvalue = 1, command=self.switch)
self.check.grid(row=0, column=3, pady=0, padx=0, sticky=E+W+N+S)
def switch(self):
if self.CheckVar_theta.get():
self.entry11.config(state=DISABLED)
else:
self.entry11.config(state=NORMAL)
if __name__=="__main__":
d=MainWindow()
d.mainloop()