Python Forum
[Tkinter] proportional fonts
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] proportional fonts
#1
Hi,
I have developed a tkinter app that is suposed to work on 1920x1080 and 1920x1200 PCs (windows).
Using :
width= root.winfo_screenwidth()
height= root.winfo_screenheight()
root.geometry(f'{width}x{height}')
I can manage that, but a vertical row of buttons sqeezes out the 2 bottom ones on 1920x1080 because the develoment pc is 1920x1200..
I suspect it's the button font size that causes the problem.
Question: does the font size of a widget (button) take priority on whatever resizeing you do
on the root window dimensions.
Is there such a thing a "proportional font sizes", or do I make a statement like:
if it is 1920x1082 use size 14, if it is 1920x1200 use font size 18 ?
thx,
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#2
Usually when making a tkinter window/widget i don't use a fixed size for that same reason. If I do I turn off the scaling.
Here is a link on changing font size with event.
https://stackoverflow.com/questions/6638...calculator
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
You can define a font to use for all your controls and at startup set that to be 14 or 18 points. You can do the same thing with a style. Either way, you have to write the code that decides what font to use. Tkinter will not do that. I do not think this is a good idea.

The correct answer is that your application should be resizeable to some minimum size that will work at all reasonable screen resolution without changing font sizes. Your windows should be resizeable by your user, and you should use layout managers that move and resize the widgets based on the size of the window, not the size of the screen. If you have layouts that cannot be resized nicely they should have scrollbars so you can move the larger scrolled view around to look at different parts (like looking at a large document in a text editor).

User interface design is not easy.
Reply
#4
Thanks for the answers, I know what to do (...try).
Of course, I could tell some of the users to buy a new 1920x1200 laptop.
However, this is not going to make me popular. Cool
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] PyQT Problems with multiple fonts DrakeSoft 2 1,543 Feb-21-2024, 04:30 AM
Last Post: wilkinsonwilfrid
  [Tkinter] Custom Fonts GalaxyCoyote 1 4,775 Dec-25-2019, 06:56 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