Choose which screen to center a frame on

Hi everyone,

I’m on Windows 10.

I have a frame that calls self.CenterOnScreen(), which successfully centers the frame on the screen. However, I have multiple screens and it’s choosing the wrong one. One of my screens is defined as my “main display”, and this is the one I want to center the frame on. How can I do that?


To my knowledge there are a couple thoughts that might work. has win-maximize (and other utilities/modules) that some how access the windows registry and determine the monitor.
That said, I believe there are many such apps out in the wild that could help. I have NOT had any need for using those modules in my apps.


I don’t have multiple monitors on my PCs, so I haven’t been able to test it, but the following article might be of use:

Thank you. I reworked the code into this:

    def center_on_screen(self, screen: int = 0) -> None:
        display = wx.Display(screen)
        display_x, display_y, display_w, display_h = display.GetGeometry()
        self.SetPosition((int(display_x + (display_w - self.Size[0]) / 2),
                          int(display_y + (display_h - self.Size[1]) / 2)))

One thing that’s missing now is the ability to detect which display is defined as the “main display” by Windows. I thought it’ll always be display 0 but I thought wrong.