第二个面板不会出现在wxpython应用程序中

时间:2014-04-14 13:26:09

标签: python user-interface wxpython

我想在另一个面板上并排(水平)放置2个面板,但第二个面板没有显示:

import wx

szflags = wx.EXPAND | wx.ALL
min_height = 50
height_ratio = 4
pborder = 10
lborder = 5
    class ChartPanel(wx.Panel):

        def __init__(self, *args, **kwargs):
            wx.Panel.__init__(self, *args, **kwargs)
            self.SetBackgroundColour(wx.Colour(226,226,226))

            self.st = wx.StaticText(self, label='CHART PANEL')
            #self.chart = bar_line.CanvasPanel(self, "320")

            sizer = wx.BoxSizer(wx.VERTICAL)
            sizer.Add(self.st, 1 , szflags , lborder)
            #sizer.Add(self.chart, 1 , szflags)
            self.SetSizer(sizer)


    class NotebookPage(wx.Panel):

        def __init__(self, *args, **kwargs):
            fleet = kwargs.pop('fleet_name', None)
            wx.Panel.__init__(self, *args, **kwargs)


            self.mainPanel = NotebookPage_MainPanel(self, name='Notebook_Page_MainPanel', fleet_name=fleet)
            self.chartPanel = ChartPanel(self, name='Notebook_Page_ChartPanel')

            sizer = wx.BoxSizer(wx.HORIZONTAL)
            sizer.Add(self.mainPanel, 1, wx.EXPAND|wx.ALL,border=10)
            sizer.Add(self.chartPanel, 1, wx.EXPAND|wx.ALL,border=10)
            self.SetSizer(sizer)

这里ChartPanel没有显示出来。上面有什么问题?

1 个答案:

答案 0 :(得分:2)

实际上你需要创建一个父面板并将两个ur面板添加到它..

创建主面板,它包含两个孩子,即笔记本页面和图表面板

    class NotebookPage(wx.Panel):

    def __init__(self, *args, **kwargs):
        fleet = kwargs.pop('fleet_name', None)
        wx.Panel.__init__(self, *args, **kwargs)

        self.masterPanel=wx.Panel(self,-1)
        self.mainPanel = NotebookPage_MainPanel(self.masterpanel, name='Notebook_Page_MainPanel', fleet_name=fleet)
        self.chartPanel = ChartPanel(self.masterpanel, name='Notebook_Page_ChartPanel')

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.mainPanel, 1, wx.EXPAND|wx.ALL,border=10)
        sizer.Add(self.chartPanel, 1, wx.EXPAND|wx.ALL,border=10)
        self.SetSizer(sizer)

参考你可以看到这个link

第二,他实施了相同的多个小组link