【发布时间】:2016-08-26 12:54:24
【问题描述】:
如果 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,它会在我无法触发的事件上发生更改。
【问题讨论】:
标签: python-2.7 wxpython boxsizer