So I made a few tutorial applications and understand the most basic Python concepts and I'm well on my way to become a Python addict, only one thing is standing between me and the road ahead. I'm trying to make my first "useful" Python application - a program that allows me to keep code snippets that I come across on my journey, almost like a journal of useful code.

But I want to do something I haven't read about yet. I have the "wxPython in Action" book, but I haven't read it through yet, I also didn't have the time to search the entire forum for similar posts, so I apologize if I make a duplicate thread.

I want to use wxPython to make more than one form and switch between them, but the most windows I had in an application was only the main form. Any help or useful resources on this topic will be greatly appreciated!

Thanks!

Dani AI

Generated

A practical, low‑friction pattern for a multi‑form wxPython app is one top‑level wx.Frame that hosts several wx.Panel subclasses—each panel implements a “form” or view. Switching views becomes a matter of Hide()/Show() on panels plus Frame.Layout(). This keeps a single window chrome, shared menus/statusbar, and avoids multiple taskbar entries. As noted, wx.Notebook (or wx.aui.AuiNotebook for advanced tabs) is perfect for tabbed UIs; for app navigation, panel swapping is usually cleaner.

Implementation notes and checklist:

  • Implement each screen as a wx.Panel subclass (e.g. SnippetListPanel, SnippetEditPanel).
  • Add all panels to the frame sizer, hide the inactive ones at startup, and expose a show_panel(name) controller to Hide the current panel, Show the target, then call self.Layout() and target.SetFocus().
  • Use wx.Dialog for modal tasks (import/edit dialogs). Create panels once and cache them rather than re-creating on every switch.
  • For message passing between panels, consider wx.lib.pubsub or a small controller object to avoid tight coupling.

Example minimal pattern:

import wx

class ListPanel(wx.Panel):
    def __init__(self, parent):
        super().__init__(parent)
        btn = wx.Button(self, label="Edit")
        btn.Bind(wx.EVT_BUTTON, parent.show_edit)

class EditPanel(wx.Panel):
    def __init__(self, parent):
        super().__init__(parent)
        btn = wx.Button(self, label="Back")
        btn.Bind(wx.EVT_BUTTON, parent.show_list)

class MainFrame(wx.Frame):
    def __init__(self):
        super().__init__(None, title="Snippets")
        self.list = ListPanel(self)
        self.edit = EditPanel(self)
        s = wx.BoxSizer(wx.VERTICAL)
        s.Add(self.list, 1, wx.EXPAND); s.Add(self.edit, 1, wx.EXPAND)
        self.SetSizer(s); self.edit.Hide(); self.Show()

    def show_edit(self, evt):
        self.list.Hide(); self.edit.Show(); self.Layout()

    def show_list(self, evt):
        self.edit.Hide(); self.list.Show(); self.Layout()

if __name__ == "__main__":
    app = wx.App(False); MainFrame(); app.MainLoop()

A few cautions: ignore the idea from about inheriting both Tk and wx—mixing GUI toolkits leads to conflicting event loops and hard‑to‑debug problems. For snippet storage use lightweight persistence (SQLite, JSON, or shelve) and keep UI logic separate from storage.

Recommended Answers

All 5 Replies

You can use wx.Notebook widget to have multiple tabs.

Is there no way I can switch windows? I have written an entire new class for the new window, can't I somehow switch to make the window use the other class with an event?

import your new class into your main programe . Then there will be a conection with the event.

Okay, and one more question, is it possible to switch between wx.Frame or should I rather replace the wx.Panel?

you can make a class that inherit both tkinter and wx.
with this you can have both world at your disposal.
;)

commented: Interesting idea! +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.