Assigning a columnspan (other than 1) to a child object appears to negate the effects of uniform=1 and grid_propagate(False). Here is a simple example of what I mean (click the text to toggle back and forth and observe the change).
import tkinter as tk
class TestInterface:
def __init__(self, master):
self.master = master
self.master.title("Interface Template")
self.master.configure(bg='#000000', relief=tk.RIDGE, borderwidth=16)
self.master.attributes('-fullscreen', True)
self.demonstration_frame = tk.Frame()
self.dummy_frame = tk.Frame()
self.button = tk.Button()
self.button1()
def button1(self):
self.remake_test_frame()
self.button = tk.Button(self.demonstration_frame, text="LONG PHRASE MODIFYING THE GRID STRUCTURE", bg='#111111',
relief=tk.FLAT, fg="#FFFFFF", font=('Courier', 12), anchor='center', borderwidth=6,
command=lambda: self.button2())
self.button.grid(row=2, column=3, columnspan=2, sticky='nsew')
def button2(self):
self.remake_test_frame()
self.button = tk.Button(self.demonstration_frame, text="LONG PHRASE BEING CUT OFF AS INTENDED", bg='#111111',
relief=tk.FLAT, fg="#FFFFFF", font=('Courier', 12), anchor='center', borderwidth=6,
command=lambda: self.button1())
self.button.grid(row=2, column=3, sticky='nsew')
def remake_test_frame(self):
self.demonstration_frame.destroy()
self.demonstration_frame = tk.Frame(master=self.master, relief=tk.FLAT, borderwidth=4, bg='blue')
self.demonstration_frame.pack(expand=True, fill="both")
self.demonstration_frame.grid_propagate(False)
for k in range(4):
self.demonstration_frame.grid_rowconfigure(k, weight=1, uniform=1)
for i in range(6):
self.demonstration_frame.grid_columnconfigure(i, weight=1, uniform=1)
for j in range(4):
self.dummy_frame = tk.Frame(self.demonstration_frame, relief=tk.RIDGE, borderwidth=1,
bg='#' + str(int(j / 2)) + str(int(j / 2)) + str(int(j / 2))
+ str(int(i / 2)) + str(int(i / 2)) + str(int(i / 2)))
self.dummy_frame.grid(row=j, column=i, sticky='nsew')
root = tk.Tk()
my_gui = TestInterface(root)
root.mainloop()
I have demonstration_frame being re-formed from scratch with each button click, so we know that frame is being created in the same way each time. The dummy_frames are just to make clear what is happening. The only difference between self.button1() and self.button2() is the removal of "columnspan=2."
I want these grid lines locked in place (I'm fine with text being invisible/off-frame). Can anyone explain why columnspan is changing the behavior of grid_propagate() here?
edit: here is the code without the demonstration_frame.destroy method. It behaves the exact same way.
import tkinter as tk
class TestInterface:
def __init__(self, master):
self.master = master
self.master.title("Interface Template")
self.master.configure(bg='#000000', relief=tk.RIDGE, borderwidth=16)
self.master.attributes('-fullscreen', True)
self.demonstration_frame = tk.Frame(master=self.master, relief=tk.FLAT, borderwidth=4, bg='blue')
self.demonstration_frame.pack(expand=True, fill="both")
self.demonstration_frame.grid_propagate(False)
for k in range(4):
self.demonstration_frame.grid_rowconfigure(k, weight=1, uniform=1)
for i in range(6):
self.demonstration_frame.grid_columnconfigure(i, weight=1, uniform=1)
for j in range(4):
self.dummy_frame = tk.Frame(self.demonstration_frame, relief=tk.RIDGE, borderwidth=1,
bg='#' + str(int(j / 2)) + str(int(j / 2)) + str(int(j / 2))
+ str(int(i / 2)) + str(int(i / 2)) + str(int(i / 2)))
self.dummy_frame.grid(row=j, column=i, sticky='nsew')
self.dummy_frame = tk.Frame()
self.button = tk.Button()
self.button1()
def button1(self):
self.button = tk.Button(self.demonstration_frame, text="LONG PHRASE MODIFYING THE GRID STRUCTURE", bg='#111111',
relief=tk.FLAT, fg="#FFFFFF", font=('Courier', 12), anchor='center', borderwidth=6,
command=lambda: self.button2())
self.button.grid(row=2, column=3, columnspan=2, sticky='nsew')
def button2(self):
self.button.destroy()
self.button = tk.Button(self.demonstration_frame, text="LONG PHRASE BEING CUT OFF AS INTENDED", bg='#111111',
relief=tk.FLAT, fg="#FFFFFF", font=('Courier', 12), anchor='center', borderwidth=6,
command=lambda: self.button1())
self.button.grid(row=2, column=3, sticky='nsew')
root = tk.Tk()
my_gui = TestInterface(root)
root.mainloop()