Python Forum
Tkinter scaling windows conten to or with its size not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter scaling windows conten to or with its size not working
#1
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:
[Image: WeWq4io.png]

And that is the result when i try to resize it:
[Image: zv0jGIU.png]

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
Detzi
Reply
#2
I wrote a tutorial on this (a long time ago) it's here: https://python-forum.io/Thread-Tkinter-G...first-time
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)
Reply
#3
Using the grid geometry manager, sticky controls how it expands http://www.effbot.org/tkinterbook/grid.htm If this does not work for you, switch over to pack which has expand and fill options http://www.effbot.org/tkinterbook/pack.htm
Reply
#4
@Larz60+
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):
    try:
        value = float(feet.get())
        meters.set((0.3048 * value * 10000.0 + 0.5)/10000.0)
    except ValueError:
        pass

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)

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

root.mainloop()
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.
Reply
#5
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: https://python-forum.io/Thread-Perfectly...oportioned
Reply
#6
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter two windows instead of one jacksfrustration 7 776 Feb-08-2024, 06:18 PM
Last Post: deanhystad
  pass a variable between tkinter and toplevel windows janeik 10 2,138 Jan-24-2024, 06:44 AM
Last Post: Liliana
  Using Tkinter inside function not working Ensaimadeta 5 4,859 Dec-03-2023, 01:50 PM
Last Post: deanhystad
  Tkinter multiple windows in the same window tomro91 1 786 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  [Tkinter] scaling DPaul 7 3,210 Jun-24-2022, 02:22 PM
Last Post: DPaul
  tkinter toggle buttons not working Nu2Python 26 6,768 Jan-23-2022, 06:49 PM
Last Post: Nu2Python
  Scaling text QLabel following display mode windows '100%, 125% ...) VIGNEAUD 2 2,217 Jul-07-2021, 06:38 PM
Last Post: deanhystad
  Tkinter menu font size -method to change tonycat 2 7,702 Oct-11-2020, 02:43 AM
Last Post: tonycat
  Dual Tkinter windows and shells Astrikor 6 3,832 Sep-03-2020, 10:09 PM
Last Post: Astrikor
  [Tkinter] Trying to change font size w/o changing button size python63 3 9,730 Aug-05-2020, 01:04 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020