DanielVd
Posts: 5
Joined: Wed Apr 09, 2014 3:27 pm

TkInter Label Change Font Size by Text Length

Wed Mar 04, 2015 4:09 pm

Goog morning,

i have a question.
I have a tkinter label with fixed width, in this label i set dynamic text, i need to change font size (decrease or increase) when the text width is longer than label width .
This is an example: Image

User avatar
paddyg
Posts: 2393
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: TkInter Label Change Font Size by Text Length

Thu Mar 05, 2015 11:23 pm

don't know official way but you could do something like

Code: Select all

t = Label(root, text="Accesso Aquafitness")
print(t.winfo_reqwidth(), t.winfo_reqheight())
then pro rata your font size according to constraint.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

DanielVd
Posts: 5
Joined: Wed Apr 09, 2014 3:27 pm

Re: TkInter Label Change Font Size by Text Length

Fri Mar 06, 2015 8:20 am

paddyg wrote:don't know official way but you could do something like

Code: Select all

t = Label(root, text="Accesso Aquafitness")
print(t.winfo_reqwidth(), t.winfo_reqheight())
then pro rata your font size according to constraint.
Thanks now i will try!

DanielVd
Posts: 5
Joined: Wed Apr 09, 2014 3:27 pm

Re: TkInter Label Change Font Size by Text Length

Fri Mar 06, 2015 9:28 am

paddyg wrote:don't know official way but you could do something like

Code: Select all

t = Label(root, text="Accesso Aquafitness")
print(t.winfo_reqwidth(), t.winfo_reqheight())
then pro rata your font size according to constraint.
Thanks, it is exactly what i wanted!

Return to “Python”