Python Forum

Full Version: Tkinter scaling windows conten to or with its size not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Good Day,
i want tkinter to scale whatever is in its frame to the size of the window. Maybe pictures make more clear what i want:
This is the way the programm looks when i open it:

And that is the result when i try to resize it:

What i actually want is that all the content in the window grows bigger with the size of the window. The code used to make this example can be found here. I also don't know if this expectation is at all plausible.

Would be nice if you could point me to tutorial or book or something similar where i can learn how to do this.

Thanks in Advance
I wrote a tutorial on this (a long time ago) it's here:
It's been a long time since I looked at it, so perhaps I would do it differently now.
If you find it isn't applicable, please let me know and I'll review and update as needed.

Also , please post your code (in code tags)
Using the grid geometry manager, sticky controls how it expands If this does not work for you, switch over to pack which has expand and fill options
the code is used can also be found on under the link i provided, but here you go:
from tkinter import *
from tkinter import ttk

def calculate(*args):
        value = float(feet.get())
        meters.set((0.3048 * value * 10000.0 + 0.5)/10000.0)
    except ValueError:

root = Tk()
root.title("Feet to Meters")

mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)

feet = StringVar()
meters = StringVar()

feet_entry = ttk.Entry(mainframe, width=7, textvariable=feet)
feet_entry.grid(column=2, row=1, sticky=(W, E))

ttk.Label(mainframe, textvariable=meters).grid(column=2, row=2, sticky=(W, E))
ttk.Button(mainframe, text="Calculate", command=calculate).grid(column=3, row=3, sticky=W)

ttk.Label(mainframe, text="feet").grid(column=3, row=1, sticky=W)
ttk.Label(mainframe, text="is equivalent to").grid(column=1, row=2, sticky=E)
ttk.Label(mainframe, text="meters").grid(column=3, row=2, sticky=W)

for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)

root.bind('<Return>', calculate)

if i am not mistaken the two lines that should take care of it are
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
i also tried it after adding
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)
but the result was the same. I have not finished reading your tutorial but to me it seems that you are also referring to the weight and the configure statements from above

@woooee thanks for the "grid" link i actually found this a bit earlier and used it to learn the grid manager. It's a nice tutorial but it didn't teach me how i can get tkinter to resize my window content.

Since i plan to place mostly entry fields and buttons in a grid, the grid manager seems to be the better choice here so that's what i used so far... Correct me if i am wrong.
Quote:if i am not mistaken the two lines that should take care of it are
correct, it is the weight that does it
If you are not too far into your project, I'd seriously think about using wxpython.
Resizing is a snap.
see my example of this here:
Quote:If you are not too far into your project, I'd seriously think about using wxpython.
Resizing is a snap
I actually was almost finished, but i gave it a shot anyway and it's way better. wxPython is the better tool here thank you for your advice. Smile