の子のサイズが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
変更することはできず、トリガーできないイベントで変更されます。