I have created a simple app using wxGlade which demonstrates the problem:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# generated by wxGlade 0.9.6 on Fri Nov 27 19:37:11 2020
#
import wx
# begin wxGlade: dependencies
# end wxGlade
# begin wxGlade: extracode
# end wxGlade
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.print_size_button = wx.Button(self, wx.ID_ANY, "Print Size")
self.close_button = wx.Button(self, wx.ID_ANY, "Close")
self.__set_properties()
self.__do_layout()
# end wxGlade
self.Bind(wx.EVT_BUTTON, self.OnClose, self.close_button)
self.Bind(wx.EVT_BUTTON, self.OnPrintSize, self.print_size_button)
self.SetSize((300, 300))
def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("Set Frame Size Test")
# end wxGlade
def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
main_sizer = wx.BoxSizer(wx.VERTICAL)
bottom_sizer = wx.BoxSizer(wx.HORIZONTAL)
top_sizer = wx.BoxSizer(wx.HORIZONTAL)
top_sizer.Add((20, 20), 1, wx.ALIGN_CENTER_VERTICAL, 0)
top_sizer.Add(self.print_size_button, 0, wx.ALIGN_CENTER_VERTICAL, 0)
top_sizer.Add((20, 20), 1, wx.ALIGN_CENTER_VERTICAL, 0)
main_sizer.Add(top_sizer, 1, wx.ALL | wx.EXPAND, 4)
static_line = wx.StaticLine(self, wx.ID_ANY)
main_sizer.Add(static_line, 0, wx.EXPAND, 0)
bottom_sizer.Add((20, 20), 1, wx.EXPAND, 0)
bottom_sizer.Add(self.close_button, 0, 0, 0)
bottom_sizer.Add((20, 20), 1, wx.EXPAND, 0)
main_sizer.Add(bottom_sizer, 0, wx.BOTTOM | wx.EXPAND | wx.TOP, 4)
self.SetSizer(main_sizer)
main_sizer.Fit(self)
self.Layout()
# end wxGlade
def OnClose(self, _event):
self.Destroy()
def OnPrintSize(self, _event):
size = self.GetSize()
print(size)
# end of class MyFrame
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, wx.ID_ANY, "")
self.SetTopWindow(self.frame)
self.frame.Show()
return True
# end of class MyApp
if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()
When I run this on a PC under wxPython 4.1.1, the border of the frame is drawn for a fraction of a second with a size of (300, 300) but it then snaps back to a smaller size and the complete frame is displayed. When I click on the “Print Size” button it outputs “(141, 104)”.
If I run the same app on a PC under Python 3.8.5, wxPython 4.1.0 gtk3 (phoenix) wxWidgets 3.1.4, Linux Mint 20, then the frame is fully displayed at size (300, 300) which is confirmed when I click on the “Print Size” button.