I recently changed the geometry manager in my program from grid to pack because of a problem trying to get the Navigatiotoolbar in the frame.
The problem is that a check button that used to be on by default is not On by default now. Here is the code for the button:
Var1=IntVar()
Var1.set(1)
c = tk.Checkbutton(self,text="Test", variable=Var1, onvalue=1, offvalue=0)
c.pack( side = LEFT )
So if I change the geometry manager I cannot longer put an ON default state?
Pd. The program runs without errors.
Here is a more complete piece of the code
class StartPage(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
Frame1 = Frame(self)
Frame1.pack(side=TOP)
Frame2 = Frame(self)
Frame2.pack( side= TOP )
Frame3 = Frame(self)
Frame3.pack( side = TOP)
Frame4 = Frame(self)
Frame4.pack( side = BOTTOM , pady=20, expand=True)
label = tk.Label(Frame1, text="Start Page")
label.pack(side=TOP)
button1=ttk.Button(Frame2, text="Visit Page 1",
command=lambda:controller.show_frame(PageOne))
button1.pack( side = LEFT )
button2=ttk.Button(Frame3, text="Page Two",
command=lambda:controller.show_frame(PageTwo) )
button2.pack( side = LEFT )
button3=ttk.Button(Frame2, text="Spider",
command=lambda:controller.show_frame(PageThree) )
button3.pack( side = LEFT )
button4=ttk.Button(Frame2, text="Ternario",
command=lambda:controller.show_frame(PageFour) )
button4.pack( side = LEFT )
button5=ttk.Button(Frame3, text="Ti-Zr-Yx3",
command=lambda:controller.show_frame(PageFive) )
button5.pack( side = LEFT )
#global Var1
Var1=IntVar()
Var1.set(1)
c = tk.Checkbutton(self,text="Test", variable=Var1, onvalue=1, offvalue=0)
c.pack( side = LEFT )
app = StartPage()
app.mainloop()
It looks like
Var1
is being garbage collected at the end of the__init__
function, making the Checkbutton forget its state before the window begins to render. One possible workaround is to save Var1 as an attribute of the instance, so it doesn't die prematurely.... Or just don't have an IntVar at all.