0

I would like the widgets on the window to expand as you expand the window. I know you can do it with the pack method but I'm using the grid method to arange my widgets.

Pack Method:

label = Label(root, text="Some Text")
label.pack(expand=1, fill=BOTH)

Grid Method I'm using:

self.inventoryLabel = Label(self.root, text="\nInventory")
self.inventoryLabel.grid(row=3, column=15, columnspan=15, rowspan=1)
2
Contributors
1
Reply
9
Views
1 Year
Discussion Span
Last Post by woooee
1

You use rowconfigure and columnconfigure. If you comment one of them out in the following example, it will only expand in the direction of which ever was not commented.

try:
    import Tkinter as tk     ## Python 2.x
except ImportError:
    import tkinter as tk     ## Python 3.x

def column_row_expandable():
    """ the labels and button will not expand when the top frame expands
        without the rowconfigure and columnconfigure statements
    """
    top=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")

    top.rowconfigure(1, weight=1)
    tk.Button(top, text="button").grid(row=1, column=0, columnspan=10, sticky="nsew")
    top.mainloop()

column_row_expandable()

Edited by woooee

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.