0

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 __name__ == "__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?

1 Answer 1

3

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()
1
  • in fact, I believe that you have to use a sizer. The docs say: "It is assumed that the ScrolledPanel will have a sizer, as it is used to calculate the minimal virtual size of the panel and etc."
    – Mark
    Jan 5, 2011 at 17:29

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.