为什么wxpython中的ScrolledPanel不能这样工作?

时间:2011-01-05 15:46:04

标签: python wxpython

我不知道为什么以下代码不起作用,请帮帮我:

import wx
import wx.lib.scrolledpanel as scrolled

class TaskFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, parent = None, id = -1, title="ScrolledPanel", size = (500, 600))
        MainPanel = wx.Panel(self)
        NewPanel = scrolled.ScrolledPanel(parent = MainPanel, pos = (100, 100), size = (300, 200), id = -1, style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER, name="panel" )

        self.Button = wx.Button(parent = NewPanel, id = -1, label="Log", pos=(500, 30), size=(50, 20))
        NewPanel.SetupScrolling()


class TaskApp(wx.App):
    def OnInit(self):
        self.frame = TaskFrame()
        self.frame.Show()
        self.SetTopWindow(self.frame)
        return True

def main():
    App = TaskApp(redirect = False)
    App.MainLoop()

if __name__ == "__main__":
    main()

Log按钮应该在NewPanel中,NewPanel应该能够滚动,但不是,问题是什么?

1 个答案:

答案 0 :(得分:3)

尝试使用sizer。你必须在其中放置一个大于ScrolledPanel的对象来激活滚动(据我所知),所以这应该做我认为你想做的事情:

class TaskFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, parent = None, id = -1, title="ScrolledPanel", size = (500, 600))
        MainPanel = wx.Panel(self)
        NewPanel = scrolled.ScrolledPanel(parent = MainPanel, pos = (100, 100), size = (300, 200), id = -1, style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER, name="panel" )

        PanelSizer  = wx.BoxSizer()
        InsidePanel = wx.Panel(NewPanel)
        self.Button = wx.Button(parent=InsidePanel, id = -1, label="Log", pos=(500, 30), size=(50, 20))
        PanelSizer.Add(InsidePanel, proportion=1)

        NewPanel.SetSizer(PanelSizer)
        NewPanel.SetupScrolling()