wxpython notebook inside boxsizer

匿名 (未验证) 提交于 2019-12-03 01:36:02

问题:

What is wrong with this code? I am trying to place a notebook on a panel that is being controlled by a boxsizer. I am new to wxpython and can't figure out what I am doing wrong. When I run it it just makes a mess in the corner :(

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

回答1:

Set sizer for left panel. See code below (esp. codes between ### 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() 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!