Tk grid won't resize properly Tk grid won't resize properly tkinter tkinter

Tk grid won't resize properly


Add a root window and columnconfigure it so that your Frame widget expands too. That's the problem, you've got an implicit root window if you don't specify one and the frame itself is what's not expanding properly.

root = Tk()root.columnconfigure(0, weight=1)app = Application(root)


I use pack for this. In most cases it is sufficient.But do not mix both!

class Application(Frame):     def __init__(self, master=None):         Frame.__init__(self, master)         self.pack(fill = X, expand  =True)         self.createWidgets()     def createWidgets(self):         self.dataFileName = StringVar()         self.fileEntry = Entry(self, textvariable=self.dataFileName)         self.fileEntry.pack(fill = X, expand = True)         self.loadFileButton = Button(self, text="Load Data", )         self.loadFileButton.pack(fill=X, expand = True)


A working example. Note that you have to explicitly set the configure for each column and row used, but columnspan for the button below is a number greater than the number of displayed columns.

## row and column expandtop=tk.Tk()top.rowconfigure(0, weight=1)for col in range(5):    top.columnconfigure(col, weight=1)    tk.Label(top, text=str(col)).grid(row=0, column=col, sticky="nsew")## only expands the columns from columnconfigure from abovetop.rowconfigure(1, weight=1)tk.Button(top, text="button").grid(row=1, column=0, columnspan=10, sticky="nsew")top.mainloop()