Second panel does not show up in wxpython application

153 views
Skip to first unread message

steve

unread,
Apr 14, 2014, 9:36:56 AM4/14/14
to wxpytho...@googlegroups.com
Hi,


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?

Werner

unread,
Apr 14, 2014, 10:15:52 AM4/14/14
to wxpytho...@googlegroups.com
Hi Steve,


On 4/14/2014 15:36, steve wrote:
Hi,


I want to place 2 panels side by side (horizontally) on another panel, but the second panel does not show up:
Don't know as it does show up for me with the slightly modified code I attach.



I tested with wxPython Phoenix 3.0.1.dev76271, but I would expect it to behave the same with at least 2.9.5+.

I suspected that it was just too small that is why I used the "WIT" (http://wiki.wxpython.org/Widget%20Inspection%20Tool), just add it to your code and press "ctrl+alt+i" and use the 'Highlight' toolbar button to see what is happening.

Hope this helps
Werner

P.S.
I think that if you attach runnable code you are likelier to get an answer.
http://wiki.wxpython.org/MakingSampleApps



twopanelssidebyside.py

steve

unread,
Apr 14, 2014, 11:40:43 AM4/14/14
to wxpytho...@googlegroups.com
Sir, I used the inspection tool, when I highlight the first child panel , I see that it consumes all main window space (it has red rectangle when I press highlight button). On the other hand, when I try yo highlight second child panel, I don't see any red rectangles, although the second child panel is listed under the inspection tree.

When I look at the sizes of panels, I see that parent panel has size (840,250), and the position of second child panel is (920,40). Is it a problem?

Werner

unread,
Apr 14, 2014, 12:28:26 PM4/14/14
to wxpytho...@googlegroups.com
Hi Steve,

On 4/14/2014 17:40, steve wrote:
> Sir,
No Sir needed, Werner will do:-)
> I used the inspection tool, when I highlight the first child panel , I
> see that it consumes all main window space (it has red rectangle when
> I press highlight button). On the other hand, when I try yo highlight
> second child panel, I don't see any red rectangles, although the
> second child panel is listed under the inspection tree.
That indicates that your real code does something different then the
code you showed us. I replaced a custom class you had used with a
wx.Panel as the custom class was not included, maybe it uses up too much
space and so there isn't any for the second panel.

You might want to use e.g. a wx.Splitter to contain the two panels to
give the user more control over how space is allocated.
>
> When I look at the sizes of panels, I see that parent panel has size
> (840,250), and the position of second child panel is (920,40). Is it a
> problem?
That could be the problem, but it sounds strange to me. Are you sure
the parenting is correct, i.e. does it show in the WIT as you expect it
to be? Maybe do a parentpanel.Layout() after you added the second child
panel.

If you still don't see it do a sample application and I or someone else
here will be able to help you.

Werner

steve

unread,
Apr 15, 2014, 1:54:40 AM4/15/14
to wxpytho...@googlegroups.com
Hi Werner,

I took your suggestion and used a splitter window instead. Then I placed 1 panel on each split. Now it is OK.

However, I want to know how to do it solely with sizers as well. How would you MAKE a panel have a minimum size and adjust its position so that you make sure it is visible?

Werner

unread,
Apr 15, 2014, 4:54:34 AM4/15/14
to wxpytho...@googlegroups.com
Hi Steve,


On 4/15/2014 7:54, steve wrote:
Hi Werner,

I took your suggestion and used a splitter window instead. Then I placed 1 panel on each split. Now it is OK.

However, I want to know how to do it solely with sizers as well. How would you MAKE a panel have a minimum size and adjust its position so that you make sure it is visible?

Reply all
Reply to author
Forward
0 new messages