Search code examples
wxwidgetssizerwxformbuilder

wx - how to create two notebooks side by side with different sizes?


I want to create a window with two notebooks. The left one should be always as narrow as possible. The right one should be as wide as possible and expand when the window is resized. Is it doable in Wx?

This is what I managed to get done in wxFormBuilder. Both notebooks always have the same widths when I resize the window. enter image description here

I tried changing the sizerItem proportion of each of them, but that obviously only changes the proportion. I want to only allow the right one to expand. Changing the wxEXPAND flag of each notebook only changes the vertical expansion and not horizontal.

Thanks for help.

Generated code:

# -*- coding: utf-8 -*-

###########################################################################
## Python code generated with wxFormBuilder (version 3.10.1-0-g8feb16b)
## http://www.wxformbuilder.org/
##
## PLEASE DO *NOT* EDIT THIS FILE!
###########################################################################

import wx
import wx.xrc

###########################################################################
## Class MyFrame1
###########################################################################

class MyFrame1 ( wx.Frame ):

        def __init__( self, parent ):
                wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

                self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )

                bSizer1 = wx.BoxSizer( wx.HORIZONTAL )

                self.m_notebook1 = wx.Notebook( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 )
                self.m_panel1 = wx.Panel( self.m_notebook1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
                self.m_notebook1.AddPage( self.m_panel1, u"a page", False )
                self.m_panel2 = wx.Panel( self.m_notebook1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
                self.m_notebook1.AddPage( self.m_panel2, u"a page", False )

                bSizer1.Add( self.m_notebook1, 1, wx.EXPAND |wx.ALL, 5 )

                self.m_notebook2 = wx.Notebook( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 )
                self.m_panel3 = wx.Panel( self.m_notebook2, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
                self.m_notebook2.AddPage( self.m_panel3, u"a page", False )
                self.m_panel4 = wx.Panel( self.m_notebook2, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
                self.m_notebook2.AddPage( self.m_panel4, u"a page", False )

                bSizer1.Add( self.m_notebook2, 1, wx.EXPAND |wx.ALL, 5 )


                self.SetSizer( bSizer1 )
                self.Layout()

                self.Centre( wx.BOTH )

        def __del__( self ):
                pass

Solution

  • You just need to set the proportion of the left item to 0 (which is the default) and of the right item to 1, which will allow it to expand to fill all the available space. It's as simple as this and it doesn't matter at all that the windows are notebooks -- the rules are the same for all windows.