python – wxPython GUI Code fails on different DPI/Resolution Settings


I use wxPython for a project to code a connection to a Database with an UI. My problem is that it needs to look good on different DPI and Resolution configurations, and this is giving me a headache.

In this code exampel i tried to extract a much positions/sizing stuff i do in my Code (so expect weird stuff) to give a discussion base for what i need to change to make my UI DPI scaling resistent.

Here is my example code:

import wx
import wx.adv

class Mywin(wx.Frame):
    def __init__(self,parent,title):
        wx.Frame.__init__(self, parent, wx.ID_ANY, title,size= (600,-1))
        
        self.SetSize(800,500)

        sizer_1 = wx.BoxSizer(wx.VERTICAL)        
        sizer_1.Add(wx.StaticText(self, size=(125,-1), label='Order ID'), 0, wx.ALL , 5)
        sizer_1.Add(wx.StaticText(self, size=(125,-1), label='Status'), 0, wx.ALL , 5)
        sizer_1.Add(wx.StaticText(self, size=(125,-1), label='Creator'), 0, wx.ALL , 5)
        sizer_1.Add((-1, 5))
        sizer_1.Add(wx.StaticText(self, size=(125,-1), label='Comment'), 0, wx.ALL , 5)
        sizer_1.Add((-1, 40))
        sizer_1.Add(wx.StaticText(self, size=(125,-1), label='Customer ID'), 0, wx.ALL , 5)
        sizer_1.Add(wx.StaticText(self, size=(125,-1), label='Customer Name'), 0, wx.ALL , 5)        
        sizer_1.Add(wx.StaticText(self, size=(125,-1), label='Contact Person'), 0, wx.ALL , 5)
        sizer_1.Add((-1, 21))
        sizer_1.Add(wx.StaticText(self, size=(125,-1), label='Inquiry Date'), 0, wx.ALL , 5)


        ctrl_height = 25
        stati = ("Test", "Example")
        
        tc_order_id = wx.TextCtrl(self, -1, size=(100, ctrl_height),style=wx.TE_PROCESS_ENTER)
        cb_status = wx.ComboBox(self,size=(100, ctrl_height), choices=stati, style=wx.CB_READONLY)        
        cb_creator = wx.ComboBox(self,size=(100, ctrl_height), choices=stati, style=wx.CB_READONLY)
        tc_comment = wx.TextCtrl(self, id=-1, value='', size=(300,55), style=wx.TE_MULTILINE|wx.SUNKEN_BORDER)        
        tc_customer_id = wx.TextCtrl(self, -1, size=(80, ctrl_height),style=wx.TE_PROCESS_ENTER)                             
        tc_customer_name = wx.TextCtrl(self, -1, size=(300, ctrl_height),style=wx.TE_READONLY)        
        tc_contact_id = wx.TextCtrl(self, -1, size=(80, ctrl_height),style=wx.TE_PROCESS_ENTER)
        
        calender_style = wx.adv.DP_DROPDOWN | wx.adv.DP_SHOWCENTURY | wx.adv.DP_ALLOWNONE
        tc_order_date = wx.adv.GenericDatePickerCtrl(self, size=(90,ctrl_height), style = calender_style)
        
        sizer_2 = wx.BoxSizer(wx.VERTICAL)
        sizer_2.Add(tc_order_id, 0)
        sizer_2.Add(cb_status,0, wx.TOP , 3)
        sizer_2.Add(cb_creator, wx.TOP , 2)
        sizer_2.Add(tc_comment, 0, wx.TOP, 9)
        sizer_2.Add(tc_customer_id, 0, wx.TOP, 4)
        sizer_2.Add(tc_customer_name, 0, wx.TOP, 4)
        sizer_2.Add(tc_contact_id, 0, wx.TOP, 4)
        sizer_2.Add(tc_order_date, 0, wx.TOP, 20)
        
        mainsizer = wx.BoxSizer(wx.HORIZONTAL)
        mainsizer.Add(sizer_1)
        mainsizer.Add(sizer_2)
        
        self.SetSizer(mainsizer)
        
        self.Centre()
        self.Show()
        self.Layout()


demo = wx.App()
Mywin(None,'Example Code')
demo.MainLoop()