Switching Between Panels In wxPython GUI

Oren Sifri
1 min readNov 24, 2020

--

Photo by Shunya Koide on Unsplash

wxPython is a powerful cross-platform GUI toolkit for the Python language. In this post I will show how to replace dynamically the content of a window in wxPython.

Normally we create a GUI window with wxPython by putting all the required visual components inside a wx.Panel object and positioning them using sizers such as wx.BoxSizer. Usually each window (or “frame” according to the wxPython terminology) contains a single main panel. But how can we create several main panels with different GUI layouts for the same window and switch between them dynamically?

Before answering this question, here is the command line for installing wxPython:

pip install wxpython

The following code snippet demonstrate how to allow switching between panels in wxPython using the PanelSwitcher class which is derived from wx.BoxSizer. You can copy the code of PanelSwitcher from the snippet below into you project.

--

--

Oren Sifri
Oren Sifri

Written by Oren Sifri

Software developer & architect. CTO at MedDev Soft

No responses yet