EDIT Now it has moved to Python 3.4.3 tkinter - the program freezes when declaring IntVar or any other tkinter data type , since this is the root of the problem that is now resolved. Basically, NEVER call ANYTHING "master" in Python 3.x using tkinter, it causes an endless loop :( My complete code is now deleted, as this is my term paper and doesn’t want people to pinch it: D EDIT
I am relatively new to tkinter and can't see where I am going wrong. I tried using StringVar () and a regular string to disable multiple input fields when the Checkbutton function is enabled. Here is the frame in which the problem is:
class CActivity(tk.Frame):
def Clear(self):
pass
def Today(self):
if self.todayVar == "ON":
self.day.configure(state="disabled")
self.month.configure(state="disabled")
self.year.configure(state="disabled")
else:
self.day.configure(state="normal")
self.month.configure(state="normal")
self.year.configure(state="normal")
def createWidgets(self):
self.title = tk.Label(self)
self.title["text"] = "Add an Activity"
self.title["font"] = ("Times New Roman",30)
self.title["fg"] = "purple"
self.title.grid(row=0,column=0,sticky="W",padx=5,pady=5)
self.todayVar = ""
tk.Label(self,text="Activity Name:",font=("Times New Roman",15)).grid(row=1,column=0,sticky="W",padx=5,pady=5)
name = tk.Entry(self).grid(row=1,column=1,columnspan=3,sticky="E",padx=5,pady=5)
tk.Label(self,text="Priority:",font=("Times New Roman",15)).grid(row=2,column=0,sticky="W",padx=5,pady=5)
priority = tk.Checkbutton(self).grid(row=2,column=1,sticky="W",padx=0,pady=5)
tk.Label(self,text="Today?",font=("Times New Roman",15)).grid(row=3,column=0,sticky="W",padx=5,pady=5)
today = tk.Checkbutton(self,onvalue="ON",offvalue="OFF",variable=self.todayVar,command=self.Today).grid(row=3,column=1,sticky="W",padx=0,pady=5)
tk.Label(self,text="Date (DD/MM/YYYY):",font=("Times New Roman",15)).grid(row=4,column=0,sticky="W",padx=5,pady=5)
day = tk.Entry(self,width=2).grid(row=4,column=1,sticky="W",padx=2,pady=5)
month = tk.Entry(self,width=2).grid(row=4,column=2,sticky="W",padx=2,pady=5)
year = tk.Entry(self,width=4).grid(row=4,column=3,sticky="W",padx=2,pady=5)
self.clear = tk.Button(self, command=self.Clear)
self.clear["text"] = "Clear"
self.clear["font"] = ("Times New Roman",15)
self.clear["fg"] = "red"
self.clear.grid(row=7,column=4,sticky="WE",padx=5,pady=5)
self.back = tk.Button(self)
self.back["text"] = "Back"
self.back["font"] = ("Times New Roman",15)
self.back["fg"] = "red"
self.back["command"] = self.parent.Menu
self.back.grid(row=8,column=4,sticky="WE",padx=5,pady=5)
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.pack()
self.parent = parent
self.createWidgets()
And here instead of StringVar () instead of the standard Python string:
class CActivity(tk.Frame):
def Clear(self):
pass
def Today(self):
if self.todayVar.get() == "ON":
self.day.configure(state="disabled")
self.month.configure(state="disabled")
self.year.configure(state="disabled")
else:
self.day.configure(state="normal")
self.month.configure(state="normal")
self.year.configure(state="normal")
def createWidgets(self):
self.title = tk.Label(self)
self.title["text"] = "Add an Activity"
self.title["font"] = ("Times New Roman",30)
self.title["fg"] = "purple"
self.title.grid(row=0,column=0,sticky="W",padx=5,pady=5)
self.todayVar = tk.StringVar()
tk.Label(self,text="Activity Name:",font=("Times New Roman",15)).grid(row=1,column=0,sticky="W",padx=5,pady=5)
name = tk.Entry(self).grid(row=1,column=1,columnspan=3,sticky="E",padx=5,pady=5)
tk.Label(self,text="Priority:",font=("Times New Roman",15)).grid(row=2,column=0,sticky="W",padx=5,pady=5)
priority = tk.Checkbutton(self).grid(row=2,column=1,sticky="W",padx=0,pady=5)
tk.Label(self,text="Today?",font=("Times New Roman",15)).grid(row=3,column=0,sticky="W",padx=5,pady=5)
today = tk.Checkbutton(self,onvalue="ON",offvalue="OFF",variable=self.todayVar,command=self.Today).grid(row=3,column=1,sticky="W",padx=0,pady=5)
tk.Label(self,text="Date (DD/MM/YYYY):",font=("Times New Roman",15)).grid(row=4,column=0,sticky="W",padx=5,pady=5)
day = tk.Entry(self,width=2).grid(row=4,column=1,sticky="W",padx=2,pady=5)
month = tk.Entry(self,width=2).grid(row=4,column=2,sticky="W",padx=2,pady=5)
year = tk.Entry(self,width=4).grid(row=4,column=3,sticky="W",padx=2,pady=5)
self.clear = tk.Button(self, command=self.Clear)
self.clear["text"] = "Clear"
self.clear["font"] = ("Times New Roman",15)
self.clear["fg"] = "red"
self.clear.grid(row=7,column=4,sticky="WE",padx=5,pady=5)
self.back = tk.Button(self)
self.back["text"] = "Back"
self.back["font"] = ("Times New Roman",15)
self.back["fg"] = "red"
self.back["command"] = self.parent.Menu
self.back.grid(row=8,column=4,sticky="WE",padx=5,pady=5)
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.pack()
self.parent = parent
self.createWidgets()
, "Checkbutton", "Checkbutton" , . StringVar() tk - . , , , .