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
#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:
İmage


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


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
Quote
#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)
Quote
#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
Quote
#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.
Quote
#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
Quote
#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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to close one of the windows in Tkinter scratchmyhead 3 272 Dec-21-2019, 06:48 PM
Last Post: pashaliski
  [Tkinter] Mouse click event not working on multiple tkinter window evrydaywannabe 2 245 Dec-16-2019, 04:47 AM
Last Post: woooee
  python file(.py) not working with my tkinter project DeanAseraf1 8 700 Jul-30-2019, 12:55 PM
Last Post: DeanAseraf1
  Using tkinter on Windows to launch python 3 scripts Mocap 1 263 Jul-17-2019, 05:16 AM
Last Post: Yoriz
  [Tkinter] sleep(n) not working inside tkinter mainloop roger31415 2 801 Jul-14-2019, 06:57 PM
Last Post: wuf
  [Tkinter] Using tkinter and mutiprocess ok on windows, locks up on ubuntu? ice 3 475 May-29-2019, 08:44 AM
Last Post: ice
  Int Variables in different Tkinter windows only returning 0 harry76 3 622 May-26-2019, 10:24 AM
Last Post: Yoriz
  tkinter - global variable not working albry 2 1,778 Jan-26-2019, 04:22 AM
Last Post: Larz60+
  [Tkinter] Ignore windows scaling in tkinter Gangwick 2 1,140 Jul-23-2018, 02:41 PM
Last Post: Gangwick
  Tkinter, button doesnt working ;// Dzonzi 3 2,821 Jul-18-2018, 11:14 AM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)