== Introduction == A Sample for the Splitter Window, less trivial than the one provided in Demo Feel free to enhance it == Special Concerns == This script uses the new wx Python package, so wxPython 2.4.1 or newer is required. == Code Sample == {{{ #!python #!/usr/bin/env python import wx class Mypanel(wx.Panel): """ Contains the buttons and the label of the window """ def __init__(self, parent): self.parent = parent wx.Panel.__init__(self, parent, pos=(6, 6), size=(200, 500)) self.SetBackgroundColour(self.parent.GetBackgroundColour()) self.splitv_button= wx.Button(self, label="Split me Vertically") self.splith_button= wx.Button(self, label="Split me Horizontally") self.parent.Bind(wx.EVT_BUTTON, self.parent.splitme, id=self.splitv_button.GetId()) self.parent.Bind(wx.EVT_BUTTON, self.parent.splitme, id=self.splith_button.GetId()) self.sp1 = None self.sp2 = None if not self.parent.label: self.txt = wx.StaticText(self, label="First Splitter") else: self.txt = wx.StaticText(self, label=self.parent.label) self.unsplit_button = wx.Button(self, label="Unsplit me") self.parent.Bind(wx.EVT_BUTTON, self.parent.unsplitme, id=self.unsplit_button.GetId()) #making a sizer box = wx.BoxSizer(wx.VERTICAL) box.Add(self.txt, 0, wx.EXPAND) box.Add(self.splitv_button, 0, wx.EXPAND) box.Add(self.splith_button, 0, wx.EXPAND) if self.parent.label: box.Add(self.unsplit_button, 0, wx.EXPAND) self.SetAutoLayout(True) self.SetSizer(box) self.Layout() self.Fit() self.Show() class Mysplitter(wx.SplitterWindow): def __init__(self, parent, title, colour): self.parent = parent self.title = title self.sp1 = None self.sp2 = None wx.SplitterWindow.__init__(self, parent, style=wx.NO_3D | wx.SP_3D) self.SetBackgroundColour(colour) try: self.number = self.parent.number+1 except: self.number = 0 if self.number > 0: self.label = self.parent.label + self.title[-1] + "." else: self.label = "" self.pn = Mypanel(self) self.pn.Show() def splitme(self,event): "split the window" button = str(event.GetEventObject().GetLabel()) if self.pn: self.pn.Destroy() self.pn = None self.sp1 = Mysplitter(self, "sp1", wx.BLUE) self.sp2 = Mysplitter(self, "sp2", wx.RED) if button == 'Split me Vertically': self.SplitVertically(self.sp1, self.sp2, 0) else: self.SplitHorizontally(self.sp1, self.sp2, 0) self.SetMinimumPaneSize(20) def unsplitme(self,event): "unsplit the parent window" self.parent.Unsplit(None) #self.parent.sp1.Destroy() #cause a segmentation fault after a while self.parent.sp1.Hide() #self.parent.sp2.Destroy() self.parent.sp2.Hide() self.parent.pn = Mypanel(self.parent) self.parent.pn.Show() self.parent.Refresh() class MyFrame(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__(self, parent, title=title, size=(800, 600), style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE) menu = wx.Menu() menu.Append(wx.ID_EXIT, "E&xit", "Terminate the program") menuBar = wx.MenuBar() menuBar.Append(menu, "&File"); self.SetMenuBar(menuBar) self.splitter = Mysplitter(self, "sp", wx.BLUE) self.Bind(wx.EVT_MENU, self.DoExit, id=wx.ID_EXIT) self.Show() def DoExit(self, event): self.Close(True) app = wx.App(False) frame = MyFrame(None, "gogo") app.MainLoop() }}} === Comments === ==== Franz Steinhaeusler ==== Thanks, I add it to the page "wxPython Demo Style Guide Update Status.