Python Forum
[Tkinter] proportional fonts - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] proportional fonts (/thread-37986.html)



proportional fonts - DPaul - Aug-17-2022

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


RE: proportional fonts - menator01 - Aug-17-2022

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/66381433/automatically-resizing-text-with-window-size-in-tkinter-calculator


RE: proportional fonts - deanhystad - Aug-17-2022

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.


RE: proportional fonts - DPaul - Aug-18-2022

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