frame.SetClientSize ≠ frame.GetSize

I want to create a frame, which width = primary display width。

so I create get display width via wx.Display

class MainDisplay:

    def __init__(self):
        for i in range(wx.Display.GetCount()):
            display = wx.Display(index=i)
            if display.IsPrimary():
                self.width = display.GetClientArea()[2]         # 主显示器宽度
                self.height = display.GetClientArea()[3]        # 主显示器高度
                self.ppi = display.GetStdPPIValue()             # 获得显示器的ppi
                self.scale = display.GetScaleFactor()           # 获取放大

and then, I pass the width and height to my frame, via self.SetClientSize

class IntroFrame(wx.Frame):

    def __init__(self, parent=None, width=None, height=None, title='答得喵'):
        wx.Frame.__init__(self, parent, wx.ID_ANY, pos=wx.DefaultPosition, title=title)

        # self.SetClientSize(width, int(min(width, height)/2))
        print(width, int(height/2))

        self.SetClientSize(width, int(height/2))


When I run the program, I get two different size:

2560 700
(2576, 739)

It seems GetSize is bigger than SetClientSize, I want to how can I fix it.

Use Frame.SetSize instead of Frame.SetClientSize.

1 Like

It works. Many Thanks

After that, I found although the width of my frame is 2560 which is the same with my display, my frame looks not the same width compare with my display, my display looks wider than my frame.

How could I make them in same width?

Many Thanks

You probably also want to use the x,y position from Display.GetClientArea and set your frame’s position to that position.

Also, in case it’s not clear, a frame’s client size is for the space inside the frame’s caption bar, borders, menu bar, tool bar and status bar, if any. The frame’s size is the size that includes everything, IOW, the outer borders and the caption bar, etc. However, on *nix there are some window managers where the outer size may not be reliable so you’ll probably want to not fully depend on that without some testing or have a fallback of some sort.

Finally, if you are wanting your frame to fill the screen then perhaps what you want to use is the ShowFullScreen method. Or perhaps just the Maximize method would do what you want.

1 Like

Thank you.

I want my frame could cover half area of display automatically ,I will try later.