2011-01-05 20 views
0

我不知道爲什麼下面的代碼不能正常工作,請大家幫我出:wxpython中的ScrolledPanel如何不以這種方式工作?

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

日誌按鈕應該在NewPanel和NewPanel應該可以滾動,但它不是,有什麼問題?

回答

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

其實,我相信你必須使用sizer。該文檔說:「假定ScrolledPanel將具有sizer,因爲它用於計算面板的最小虛擬大小等。」 – Mark 2011-01-05 17:29:47

+0

非常感謝,夥計們! – Shane 2011-01-06 03:23:37

相關問題