0

Situation:

  • I'm making a software that has to be full screen
  • It is all UIs and interfaces.
  • I want it to work on computers with screens that have different resolutions - So I need the GUI to adjust to the screen size: text will be smaller if the screen resolution is smaller, but it will still be in the middle of the screen
  • I've tried not using numbers in deciding the position of the text, but instead getting the screen resolution, and multiplying it

Problem:

The text is not getting smaller.

Question:

Is there an easy solution for my problem? Is there a module in python for this purpose? I'm currently using WxPython but I'm open to use any other GUI module.

def Title(object):
    (sizeX, sizeY) = object.GetSize()
    (displayX, displayY) = wx.GetDisplaySize()
    print(displayX)
    print(displayY)
    print(sizeX)
    print(sizeY)
    object.SetPosition((displayX/2 - sizeX/2, displayY*0.01))
Rene Knop
  • 1,788
  • 3
  • 15
  • 27
RoBaMe
  • 15
  • 2
  • You will also probably want to make sure you set the appropriate DPI scaling as well, as you'll probably want text (and icons) to be bigger on a 15" 4k display than a 27" 4k display. [This answer](https://stackoverflow.com/a/34133102/3220135) shows one way to do it. – Aaron Dec 21 '18 at 17:48

1 Answers1

0

To adjust the text size to be appropriate to the screen size, you would have to define a custom font size.
Although I suspect that the default font size will already be roughly correct, as the user will have set the system font size, based on the screen size.

You can get the current font size as follows:

self.font = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT)
point_size = self.font.GetPointSize()

Define a new, appropriate, font size based on the result from wx.GetDisplaySize():

self.font.SetPointSize(new size)

Then use SetFont(font) on the items in your UI:

self.panel.SetFont(self.font)
Rolf of Saxony
  • 21,661
  • 5
  • 39
  • 60
  • How would I use the information I'm getting from wx.GetDisplaySize() in deciding the new font size? – RoBaMe Dec 22 '18 at 21:09
  • I assume that given that there are set display sizes, that you will calculate or decide by trial and error, an appropriate font size for each, as only you know the size and layout of your UI. – Rolf of Saxony Dec 23 '18 at 09:44