- wxPython Tutorial
- wxPython - Home
- wxPython - Introduction
- wxPython - Environment
- wxPython - Hello World
- wxPython - GUI Builder Tools
- wxPython - Major Classes
- wxPython - Event Handling
- wxPython - Layout Management
- wxPython - Buttons
- wxPython - Dockable Windows
- Multiple Document Interface
- wxPython - Drawing API
- wxPython - Drag and Drop
- wxPython Resources
- wxPython - Quick Guide
- wxPython - Useful Resources
- wxPython - Discussion
wxPython - SplitterWindow Class
Object of this class is a layout manager, which holds two subwindows whose size can be changed dynamically by dragging the boundaries between them. The Splitter control gives a handle that can be dragged to resize the controls.
wx.SplitterWindow class has a very basic constructor with all parameters having usual default values.
wx.SplitterWindow(self, id, pos, size, style)
The list of predefined values for style parameter is as follows −
S.N. | Parameters & Description |
---|---|
1 | wxSP_3D Draws a 3D effect border and sash |
2 | wxSP_THIN_SASH Draws a thin sash |
3 | wxSP_3DSASH Draws a 3D effect sash (part of default style) |
4 | wxSP_BORDER Draws a standard border |
5 | wxSP_NOBORDER No border (default) |
6 | wxSP_PERMIT_UNSPLIT Always allow to unsplit, even with the minimum pane size other than zero |
Event binders for SplitterWindow class −
S.N. | Events & Description |
---|---|
1 | EVT_SPLITTER_SASH_POS_CHANGING() The sash position is in the process of being changed |
2 | EVT_SPLITTER_SASH_POS_CHANGED() The sash position was changed |
3 | EVT_SPLITTER_UNSPLIT() The splitter has been just unsplit |
4 | EVT_SPLITTER_DCLICK() The sash was double clicked. The default behavior is to unsplit the window when this happens |
The following code demonstrates the functioning of SplitterWindow. The splitter object is added to the top level frame.
splitter = wx.SplitterWindow(self, -1)
A Panel is designed to hold a multi-line TextCtrl object.
b = wx.BoxSizer(wx.HORIZONTAL) self.text = wx.TextCtrl(panel1,style = wx.TE_MULTILINE) b.Add(self.text, 1, wx.EXPAND) panel1.SetSizerAndFit(b)
A ListBox object is placed in another panel.
panel2 = wx.Panel(splitter, -1) languages = ['C', 'C++', 'Java', 'Python', 'Perl', 'JavaScript', 'PHP', 'VB.NET', 'C#'] lst = wx.ListBox(panel2, size = (100,300), choices = languages, style = wx.LB_SINGLE) hbox1 = wx.BoxSizer(wx.HORIZONTAL) hbox1.Add(lst,1) panel2.SetSizer(hbox1)
The splitter object is vertically split and two panels are added to two subwindows. The width of subwindows can be resized with the help of sash.
splitter.SplitVertically(panel2, panel1)
The complete listing of code is as follows −
import wx class Mywin(wx.Frame): def __init__(self, parent, title): super(Mywin, self).__init__(parent, title = title,size = (350,300)) splitter = wx.SplitterWindow(self, -1) panel1 = wx.Panel(splitter, -1) b = wx.BoxSizer(wx.HORIZONTAL) self.text = wx.TextCtrl(panel1,style = wx.TE_MULTILINE) b.Add(self.text, 1, wx.EXPAND) panel1.SetSizerAndFit(b) panel2 = wx.Panel(splitter, -1) languages = ['C', 'C++', 'Java', 'Python', 'Perl', 'JavaScript', 'PHP' ,'VB.NET' ,'C#'] lst = wx.ListBox(panel2, size = (100,300), choices = languages, style = wx.LB_SINGLE) hbox1 = wx.BoxSizer(wx.HORIZONTAL) hbox1.Add(lst,1) panel2.SetSizer(hbox1) splitter.SplitVertically(panel2, panel1) self.Centre() self.Bind(wx.EVT_LISTBOX, self.onListBox, lst) self.Show(True) def onListBox(self, event): self.text.AppendText( "Current selection: " + event.GetEventObject().GetStringSelection() +"\n") ex = wx.App() Mywin(None,'Splitter Demo') ex.MainLoop()
The above code produces the following output −