How to create a splitter window (Phoenix)

Keywords : Splitter window.


Introduction :

This widget enables to split the main area of an application into parts.

The user can dynamically resize those parts with the mouse pointer.

Such a solution can be seen in mail clients (evolution) or in burning software (k3b).

You can split an area vertically or horizontally.

(info by ZetCode / Jan Bodnar).


Demonstrating :

Tested py3.x, wx4.x and Win10.

Are you ready to use some samples ? ;)

Test, modify, correct, complete, improve and share your discoveries ! (!)


Sample one

img_sample_one.png

   1 # Sample_one.py
   2 
   3 """
   4 
   5 Author : Jan Bodnar
   6 Website : zetcode.com
   7 
   8 """
   9 
  10 import wx
  11 
  12 # class MyFrame
  13 # class MyApp
  14 
  15 #---------------------------------------------------------------------------
  16 
  17 class MyFrame(wx.Frame):
  18     def __init__(self, parent, id, title):
  19         wx.Frame.__init__(self, None, -1, title, size=(350, 300))
  20 
  21         self.SetIcon(wx.Icon('./icons/wxwin.ico', wx.BITMAP_TYPE_ICO))
  22 
  23         #------------
  24 
  25         splitter = wx.SplitterWindow(self, -1)
  26         splitter.SetMinimumPaneSize(20)
  27 
  28         panel1 = wx.Panel(splitter, -1)
  29         panel1.SetBackgroundColour(wx.LIGHT_GREY)
  30 
  31         wx.StaticText(panel1, -1,
  32                       "Whether you think that you can, or that you can't, you are usually right."
  33                       "\n\n Henry Ford",
  34                       (100,100), style=wx.ALIGN_CENTRE)
  35 
  36         panel2 = wx.Panel(splitter, -1)
  37         panel2.SetBackgroundColour(wx.YELLOW)
  38 
  39         splitter.SplitVertically(panel1, panel2)
  40 
  41         #------------
  42 
  43         self.Centre()
  44 
  45 #---------------------------------------------------------------------------
  46 
  47 class MyApp(wx.App):
  48     def OnInit(self):
  49         frame = MyFrame(None, -1, 'wx.SplitterWindow')
  50         frame.Show(True)
  51         self.SetTopWindow(frame)
  52 
  53         return True
  54 
  55 #---------------------------------------------------------------------------
  56 
  57 app = MyApp(0)
  58 app.MainLoop()


Sample two

img_sample_two.png

   1 # sample_two.py
   2 
   3 """
   4 
   5 https://maku77.github.io/python/wxpython/splitterwindow.html
   6 
   7 wx.SplitterWindow(Window parent, int id=-1, Point pos=DefaultPosition,
   8     Size size=DefaultSize, long style=SP_3D, String name=SplitterNameStr) -> SplitterWindow
   9 
  10 wx.SPLIT_VERTICAL
  11 wx.SPLIT_HORIZONTAL
  12 
  13 """
  14 
  15 import wx
  16 
  17 # class MyFrame
  18 # class MyApp
  19 
  20 #---------------------------------------------------------------------------
  21 
  22 class MyFrame(wx.Frame):
  23     def __init__(self, parent, id, title):
  24         wx.Frame.__init__(self, None, -1, title, size=(300, 200))
  25 
  26         self.SetIcon(wx.Icon('./icons/wxwin.ico', wx.BITMAP_TYPE_ICO))
  27 
  28         #------------
  29 
  30         self.InitializeComponents()
  31 
  32     #-----------------------------------------------------------------------
  33 
  34     def InitializeComponents(self):
  35         sp = wx.SplitterWindow(self)
  36 
  37         p1 = wx.Panel(sp, style=wx.SUNKEN_BORDER)
  38         p1.SetBackgroundColour('#fc751b')
  39 
  40         p2 = wx.Panel(sp, style=wx.SUNKEN_BORDER)
  41         p2.SetBackgroundColour('#1bb4fc')
  42 
  43         sp.SplitVertically(p1, p2, 100)  # Split the window left and right.
  44         sp.SetMinimumPaneSize(1)         # Minimum size of subwindow.
  45 
  46 #---------------------------------------------------------------------------
  47 
  48 class MyApp(wx.App):
  49     def OnInit(self):
  50         frame = MyFrame(None, -1, 'wx.SplitterWindow')
  51         frame.Show(True)
  52         self.SetTopWindow(frame)
  53 
  54         return True
  55 
  56 #---------------------------------------------------------------------------
  57 
  58 app = MyApp(0)
  59 app.MainLoop()


Download source

source.zip


Additional Information

Link :

- - - - -

https://wiki.wxpython.org/TitleIndex

https://docs.wxpython.org/


Thanks to

Jan Bodnar (sample_one.py coding), Maku77 (sample_two.py coding), the wxPython community...


About this page

Date(d/m/y) Person (bot) Comments :

04/01/21 - Ecco (Created page for wxPython Phoenix).


Comments

- blah, blah, blah....

How to create a splitter window (Phoenix) (last edited 2021-01-05 17:54:40 by Ecco)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.