Switching Between Panels In wxPython GUI
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.