如果 a 中子项的大小发生wx.BoxSizer
变化,则 boxsizer 不会重新布局:
import wx
class MyButton(wx.Button):
def __init__(self, parent):
wx.Button.__init__(self, parent, -1, style=wx.SUNKEN_BORDER, label="ABC")
self.Bind(wx.EVT_BUTTON, self.OnClick)
def OnClick(self, event):
self.SetSize((200, 200))
self.SetSizeHints(200, 200)
class MyFrame(wx.Frame):
def __init__(self, parent, ID, title):
wx.Frame.__init__(self, parent, ID, title, size=(300, 250))
self.button = MyButton(self)
button2 = wx.Button(self, -1, style=wx.SUNKEN_BORDER, label="DEF")
# self.button.Bind(wx.EVT_SIZE, self.OnButtonResize)
box = wx.BoxSizer(wx.HORIZONTAL)
box.Add(self.button, 1, wx.EXPAND)
box.Add(button2, 1, wx.EXPAND)
self.SetAutoLayout(True)
self.SetSizer(box)
self.Layout()
def OnButtonResize(self, event):
event.Skip()
self.Layout()
app = wx.App()
frame = MyFrame(None, -1, "Sizer Test")
frame.Show()
app.MainLoop()
如果在按钮(注释行)的大小调整上手动重新布局,则将获得无休止的递归。
在我的实际用例中,我无法更改MyButton
,并且MyButton
是wx.Panel
我无法触发的事件的更改。