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
#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


Messages In This Thread
RE: Tkinter scaling windows conten to or with its size not working - by Detzi - Jan-10-2020, 08:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter multiple windows in the same window hosierycouch 1 138 May-30-2024, 04:28 AM
Last Post: deanhystad
  tkinter two windows instead of one jacksfrustration 7 1,127 Feb-08-2024, 06:18 PM
Last Post: deanhystad
  pass a variable between tkinter and toplevel windows janeik 10 2,847 Jan-24-2024, 06:44 AM
Last Post: Liliana
  Using Tkinter inside function not working Ensaimadeta 5 5,341 Dec-03-2023, 01:50 PM
Last Post: deanhystad
  Tkinter multiple windows in the same window tomro91 1 1,040 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  [Tkinter] scaling DPaul 7 3,757 Jun-24-2022, 02:22 PM
Last Post: DPaul
  tkinter toggle buttons not working Nu2Python 26 7,540 Jan-23-2022, 06:49 PM
Last Post: Nu2Python
  Scaling text QLabel following display mode windows '100%, 125% ...) VIGNEAUD 2 2,341 Jul-07-2021, 06:38 PM
Last Post: deanhystad
  Tkinter menu font size -method to change tonycat 2 8,029 Oct-11-2020, 02:43 AM
Last Post: tonycat
  Dual Tkinter windows and shells Astrikor 6 4,161 Sep-03-2020, 10:09 PM
Last Post: Astrikor

Forum Jump:

User Panel Messages

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