我遇到了一个包含wx.ScrolledWindow
的{{1}}的行为问题。我在PyCollapsiblePane
中使用了示例代码,并对其做了一些修改(使用wx.lib.agw.pycollapsiblepane
对崩溃/扩展事件有反应):
wx.ScrolledWindow
展开可折叠窗格时,我希望滚动窗口添加滚动条,因为在框架中无法看到所有内容。但是当前的行为是没有滚动条出现。仅当使用鼠标手动调整整个窗口的大小时,滚动条才开始出现(当可折叠窗格再次折叠时,滚动条也不会消失)。
到目前为止我尝试过的事情:
import wx
import wx.lib.agw.pycollapsiblepane as PCP
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, size=wx.Size(600, 200), name="PyCollapsiblePane Demo")
self.panel = wx.ScrolledWindow(self)
title = wx.StaticText(self.panel, label="PyCollapsiblePane")
title.SetFont(wx.Font(18, wx.FONTFAMILY_SWISS, wx.FONTSTYLE _NORMAL, wx.FONTWEIGHT_BOLD))
title.SetForegroundColour("blue")
self.cp = cp = PCP.PyCollapsiblePane(self.panel, label="Some Data", style=wx.CP_DEFAULT_STYLE )
self.MakePaneContent(cp.GetPane())
self.panel.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnPaneChanged, self.cp)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(title, 0, wx.ALL, 25)
sizer.Add(cp, 0, wx.RIGHT | wx.LEFT | wx.EXPAND, 25)
width, height = sizer.GetMinSize()
self.panel.SetScrollbars(10, 10, width/10, height/10)
self.panel.SetSizer(sizer)
sizer.Layout()
def OnPaneChanged(self, event):
print("Re-Layout")
self.panel.Layout()
def MakePaneContent(self, pane):
''' Just makes a few controls to put on `PyCollapsiblePane`. '''
nameLbl = wx.StaticText(pane, -1, "Name:")
name = wx.TextCtrl(pane, -1, "");
addrLbl = wx.StaticText(pane, -1, "Address:")
addr1 = wx.TextCtrl(pane, -1, "");
addr2 = wx.TextCtrl(pane, -1, "");
cstLbl = wx.StaticText(pane, -1, "City, State, Zip:")
city = wx.TextCtrl(pane, -1, "", size=(150,-1));
state = wx.TextCtrl(pane, -1, "", size=(50,-1));
zip = wx.TextCtrl(pane, -1, "", size=(70,-1));
addrSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
addrSizer.AddGrowableCol(1)
addrSizer.Add(nameLbl, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
addrSizer.Add(name, 0, wx.EXPAND)
addrSizer.Add(addrLbl, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
addrSizer.Add(addr1, 0, wx.EXPAND)
addrSizer.Add((5,5))
addrSizer.Add(addr2, 0, wx.EXPAND)
addrSizer.Add(cstLbl, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
cstSizer = wx.BoxSizer(wx.HORIZONTAL)
cstSizer.Add(city, 1)
cstSizer.Add(state, 0, wx.LEFT | wx.RIGHT, 5)
cstSizer.Add(zip)
addrSizer.Add(cstSizer, 0, wx.EXPAND)
border = wx.BoxSizer()
border.Add(addrSizer, 1, wx.EXPAND | wx.ALL, 5)
pane.SetSizer(border)
# our normal wxApp-derived class, as usual
app = wx.App(0)
frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()
而非self.Layout()
self.panel.Layout()
的不同样式我正在使用:
感谢您的帮助。
答案 0 :(得分:0)
使用
self.panel.PostSizeEvent()