Creating a splitter window

In wxPython, a splitter window is an instance of the class wx.SplitterWindow. Unlike most other wxPython widgets, splitter windows require further initialization after they are created before they can be used. The constructor is pretty straightforward.

Figure 8.10 A sample splitter window after initialization

wx.SplitterWindow(parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.SP_3D, name="splitterWindow")

The parameters have the standard meanings—parent is the container for the widget, pos is the widget's location on its parent, size is its size.

After creating the splitter window, you must call one of three methods on the window before it can be used. If you want your splitter to initially display with only one sub-window, call Initialize(window), where the window parameter is the single sub-window (typically a kind of wx.Panel). In this case, the window will split later on in response to some user action.

To display the splitter already split, use either SplitHorizontally (window1, window2, sashPosition=0) or SplitVertically(window1, window2, sashPosition= 0). Both methods work similarly, with the window1 and window2 parameters containing the two sub-windows, and the sashPosition parameter containing the initial location of the sash. For the horizontal version, window1 is placed on top of window2. If the sashPosition is a positive number, it represents the initial height of the top window (i.e., the sash is that number of pixels from the top). If sashPosition is a negative number, it defines the size of the bottom window, or the number of pixels from the bottom. If the sashPosition is 0, then the sash goes in the exact middle of the splitter. In the vertical split method, window1 is on the left, and window2 is on the right. Again, a positive sashPosition sets the size of window1 and is the number of pixels the sash is from the left border. A negative sashPosition similarly sets the size of the right window, and an 0 puts the sash in the center. If your sub-windows are complex, we recommend that you use sizers in the layout so that they react gracefully to the window resizing when the sash is moved.

Was this article helpful?

+4 -3

Post a comment