I'm creating a Tkinter application that has a frame within the GUI the changes depending on what the user is doing in the program. It seems to work as far as switching between which frame is being show. However, the spinbox widget changes its size every time you go back to the frame it is located in. I tried using a fixed width using width=5
, but still encountered the same problem. I also tried using pack()
instead of grid()
. What is causing it to change shape and how do I stop it?
import tkinter as tk
from tkinter import ttk
class ODE_Solver_App(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
equation_settings = ttk.Frame(self)
equation_settings.pack(side="top", fill="both", expand = True)
equation_settings.grid_rowconfigure(0, weight=1)
equation_settings.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (ODE_Equation_Settings, System_Equation_Settings):
frame = F(equation_settings, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(ODE_Equation_Settings)
# Buttons in the main class for switching between frames.
button1 = tk.Button(self, text="ODE Settings", command=lambda: self.show_frame(ODE_Equation_Settings))
button1.pack()
button2 = tk.Button(self, text="System Settings", command=lambda: self.show_frame(System_Equation_Settings))
button2.pack()
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class ODE_Equation_Settings(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
equation_profile = tk.Frame(self) # I am going to have more frames in this class.
equation_profile.pack()
order_label = tk.Label(equation_profile, text="Order:")
order_label.grid(row=0, column=0, sticky="w")
order_select = tk.Spinbox(equation_profile, width=5, from_=1, to=100000) # This is the spinbox that is changing in size.
order_select.grid(row=0, column=1, sticky="e")
class System_Equation_Settings(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="This is Another Page!")
label.pack(pady=10,padx=10)
button1 = tk.Button(self, text="This does nothing yet...")
button1.pack()
app = ODE_Solver_App()
app.mainloop()
I am using Python 3.4 on Yosemite
EDIT: I tried running the program on different computers. The results are as follows: Mac OS Mavericks - Same exact issue. Windows XP (virtual machine on mac) - Works just fine.
It seems as though the problem is related to the OS I'm using.