EDIT This has now moved to Python 3.4.3 tkinter - Program freezes on declaration of IntVar or any other tkinter data type as that is the root of the problem which has now been solved. Basically, NEVER name ANYTHING "master" in Python 3.x using tkinter, it causes an infinite loop :( . My full code has now been removed as it is my coursework and wouldn't want people nicking it :D EDIT
I'm relatively new to tkinter and can't see where I'm going wrong. I have tried using a StringVar() and a regular string to get multiple entry fields to disable when a Checkbutton is on. Here's the frame that the problem is in:
class CActivity(tk.Frame):
def Clear(self):
pass # To be completed
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) #problem possibly on this line
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 it is with a StringVar() instead of a standard Python string:
class CActivity(tk.Frame):
def Clear(self):
pass # To be completed
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()
In the case of the use of a standard string the program runs fine until you click on the Checkbutton at which point the Checkbutton goes grey then the program stops responding. In the case of the use of the StringVar() the tk window doesn't load at all, due to this frame being initialised during the initialisation of the window. Thanks for your help and if you would like the full code to help find the problem just let me know.