开发者

How come ScrolledPanel in wxpython not working this way?

I don't know why the following code not working, please help me out:

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 __na开发者_运维知识库me__ == "__main__":
    main()

The Log button should be in the NewPanel, and the NewPanel should be able to scroll, but it's not, what's the problem?


Try using a sizer. You have to place an object larger than the ScrolledPanel inside it to activate the scrolling (as far as I know), so this should do what I think you're trying to do:

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()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜