Reputation: 408
My goal is to create 3 equally sized columns in tkinter and then be able to fill them with whatever I want. What I'm trying to do is similar to the grid system in bootstrap but in tkinter adding something in a column makes the column bigger.
My question is then, how can you create fix sized columns ?
Thanks !
the code that creates columns that are not equal :
class MainPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent, background = "black")
self.columnconfigure(0, weight = 1)
self.columnconfigure(1, weight = 1)
self.columnconfigure(2, weight = 1)
self.rowconfigure(0, weight = 1)
self.rowconfigure(1, weight = 1)
label = tk.Label(self, text = "Weather", fg = "white", bg="green", font = LARGE_FONT)
label.grid(row = 0, column = 0, padx = 0, pady = 0, sticky = 'new')
label = tk.Label(self, text = "Time", fg = "white", bg="blue", font = LARGE_FONT)
label.grid(row = 0, column = 1, pady = 0, sticky = 'nwe')
label = tk.Label(self, text = "Test", fg = "white", bg="red", font = LARGE_FONT)
label.grid(row = 0, column = 2, pady = 0, sticky = 'nwe')
label2 = tk.Label(self, text = "News", fg = "white", bg="black", font = LARGE_FONT)
label2.grid(row = 1, column = 0, padx = 0, pady = 10, sticky = 'sw')
Upvotes: 0
Views: 664
Reputation: 386342
grid
has an option specifically for equally sized columns and rows: uniform
. It takes any string as a value, and all columns with the same value will be the same size.
In your case it would look like this:
self.columnconfigure(0, weight = 1, uniform="x")
self.columnconfigure(1, weight = 1, uniform="x")
self.columnconfigure(2, weight = 1, uniform="x")
Upvotes: 2