Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Tkinter scaling windows conten to or with its size not working
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

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Dual Tkinter windows and shells Astrikor 6 247 Sep-03-2020, 10:09 PM
Last Post: Astrikor
  [Tkinter] Trying to change font size w/o changing button size python63 3 976 Aug-05-2020, 01:04 AM
Last Post: Larz60+
  python file(.py) not working with my tkinter project DeanAseraf1 9 1,456 Mar-22-2020, 10:58 PM
Last Post: ifigazsi
  How to close one of the windows in Tkinter scratchmyhead 3 841 Dec-21-2019, 06:48 PM
Last Post: pashaliski
  [Tkinter] Mouse click event not working on multiple tkinter window evrydaywannabe 2 840 Dec-16-2019, 04:47 AM
Last Post: woooee
  Using tkinter on Windows to launch python 3 scripts Mocap 1 536 Jul-17-2019, 05:16 AM
Last Post: Yoriz
  [Tkinter] sleep(n) not working inside tkinter mainloop roger31415 2 1,679 Jul-14-2019, 06:57 PM
Last Post: wuf
  [Tkinter] Using tkinter and mutiprocess ok on windows, locks up on ubuntu? ice 3 799 May-29-2019, 08:44 AM
Last Post: ice
  Int Variables in different Tkinter windows only returning 0 harry76 3 1,200 May-26-2019, 10:24 AM
Last Post: Yoriz
  tkinter - global variable not working albry 2 2,928 Jan-26-2019, 04:22 AM
Last Post: Larz60+

Forum Jump:

Users browsing this thread: 1 Guest(s)