简体   繁体   中英

Second panel does not show up in wxpython application

I want to place 2 panels side by side (horizontally) on another panel, but the second panel does not show up:

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)

Here ChartPanel doesn't show up. What is wrong above?

actually you need create a Parent Panel and add the two of ur panels to it ..

create Master panel it contains two childs thats ur notebookpage and chart panel

    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)

reference u can see this link

second he implemented same multiple panels link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM