2013-07-28 46 views
1

這段代碼有什麼問題?我正試圖在由boxsizer控制的面板上放置筆記本。我是wxpython的新手,無法弄清楚我做錯了什麼。當我運行它,它只是使一個爛攤子在角落裏爲:(左側面板wxpython筆記本里面的boxsizer

import wx 


class TestNoteBook(wx.Frame): 
    def __init__(self, parent, id, title): 
     wx.Frame.__init__(self, parent, id, title, size=(600, 500)) 



     panel = wx.Panel(self) 

     hsizer = wx.BoxSizer(wx.HORIZONTAL) 

     leftpanel = wx.Panel(panel) 

     notebook = wx.Notebook(leftpanel) 

     posterpage = wx.Panel(notebook) 
     listpage = wx.Panel(notebook) 
     notebook.AddPage(posterpage, 'posters') 
     notebook.AddPage(listpage, 'list') 

     hsizer.Add(leftpanel, 1, wx.EXPAND) 

     rightpanel = wx.Panel(panel) 

     hsizer.Add(rightpanel, 1, wx.EXPAND) 

     panel.SetSizer(hsizer) 




app = wx.App() 
frame = TestNoteBook(None, -1, 'notebook') 
frame.Show() 
app.MainLoop() 

回答

2

設置分級機。請參見下面的代碼(特別是碼### Added code ( ... ### Added code)之間)。

import wx 

class TestNoteBook(wx.Frame): 
    def __init__(self, parent, id, title): 
     wx.Frame.__init__(self, parent, id, title, size=(600, 500)) 
     panel = wx.Panel(self) 
     hsizer = wx.BoxSizer(wx.HORIZONTAL) 

     leftpanel = wx.Panel(panel) 
     notebook = wx.Notebook(leftpanel) 
     posterpage = wx.Panel(notebook) 
     listpage = wx.Panel(notebook) 
     notebook.AddPage(posterpage, 'posters') 
     notebook.AddPage(listpage, 'list') 
     hsizer.Add(leftpanel, 1, wx.EXPAND) 
     rightpanel = wx.Panel(panel) 
     hsizer.Add(rightpanel, 1, wx.EXPAND) 

     ##### Added code (
     leftpanel_sizer = wx.BoxSizer(wx.HORIZONTAL) 
     leftpanel_sizer.Add(notebook, 1, wx.EXPAND) 
     leftpanel.SetSizer(leftpanel_sizer) 

     rightpanel.SetBackgroundColour('blue') # not needed, to distinguish rightpanel from leftpanel 
     ##### Added code) 

     panel.SetSizer(hsizer) 


app = wx.App() 
frame = TestNoteBook(None, -1, 'notebook') 
frame.Show() 
app.MainLoop() 
+0

真棒。謝謝! – phimath

相關問題