0

Now I now that there are already tons of similar questions out there but none of them have worked and many are outdated. From what I've gathered people are always recommending the grid_rowconfigure and grid_columnconfigure, but that doesn't deal with text sizes. Here's a simple example:

from tkinter import *
root=Tk()

l1 = Label(root, text="This", borderwidth=2, relief="groove")
l1.grid(row=0,column=0,sticky='NSEW')

l2 = Label(root, text="That", borderwidth=2, relief="groove")
l2.grid(row=0,column=1,sticky='NSEW')

for i in range(1):
    root.grid_rowconfigure(i, weight=1)
for i in range(2):
    root.grid_columnconfigure(i, weight=1)

root.mainloop()

I found this site but it's from 2010 and copy pasting it got me no results (after dealing with import names of course)

JackU
  • 1,406
  • 3
  • 15
  • 43
Nathan Tew
  • 432
  • 1
  • 5
  • 21

1 Answers1

0

I've found that this will work:

from tkinter import *
import tkinter.font as tkFont
root=Tk()

my_font = tkFont.Font(size=10)
def resizer(event):
   if event.width in range(200,225):
      my_font.configure(size=10)   
   elif event.width in range(226,300):
      my_font.configure(size=20)
   elif event.width > 300:
      my_font.configure(size=30)

l1 = Label(root, text="This", borderwidth=2, relief="groove", font=my_font)
l1.grid(row=0,column=0,sticky='NSEW')

l2 = Label(root, text="That", borderwidth=2, relief="groove", font=my_font)
l2.grid(row=0,column=1,sticky='NSEW')

for i in range(1):
    root.grid_rowconfigure(i, weight=1)
for i in range(2):
    root.grid_columnconfigure(i, weight=1)

root.bind("<Configure>", resizer)
root.mainloop()

You can change the range(200,225) etc. To suit your needs, and in extra elif if required.

This was found from this answer. And edited to fit in within this script.

JackU
  • 1,406
  • 3
  • 15
  • 43
  • Hm I some mathematical function that maps `event.width` to a desired font size would complete this solution and negate the need for a bunch of hardcoded else if statements. However it probably still wouldn’t be as smooth as those dynamic web pages. Any idea how to do that? – Nathan Tew Jan 28 '19 at 01:12
  • @NathanTew As Bryan Oakley said, they is no tkinter feature to this. I believe this would be your best option. – JackU Jan 28 '19 at 16:14