Search code examples
pythonwxpython

How to link into new page using button in wxPython


I was trying to make a simple GUI with wxPython in which I can switch in between two or more pages using some buttons but I am not able to do so . Please tell me something by which I can link those pages using a button in wxPython. I have tried to google it but there was nothing I can find useful regarding this. Tell me if this is possible to link 2 pages or not.


Solution

  • I hope I understood correctly, you are going to make a windows GUI which is included by a menu consists of some items!. As mentioned in the comment, personally I use wxGlage which is a GUI designer written in Python with the popular GUI toolkit wxPython, that helps you create wxWidgets/wxPython user interfaces. At the moment it can generate Python, C++, Perl, Lisp and XRC (wxWidgets' XML resources) code.

    However, if you need write for yourself any single word by means of wxPython as you said you can use wxNotebook, you can use this code:

    import random
    import wx
    
    class TabPanel(wx.Panel):
        #----------------------------------------------------------------------
        def __init__(self, parent):
            """"""
            wx.Panel.__init__(self, parent=parent)
    
            colors = ["red", "blue", "gray", "yellow", "green"]
            self.SetBackgroundColour(random.choice(colors))
    
            btn = wx.Button(self, label="Press Me")
            sizer = wx.BoxSizer(wx.VERTICAL)
            sizer.Add(btn, 0, wx.ALL, 10)
            self.SetSizer(sizer)
     class DemoFrame(wx.Frame):
        """
        Frame that holds all other widgets
        """
    
        def __init__(self):
            """Constructor"""        
            wx.Frame.__init__(self, None, wx.ID_ANY, 
                              "Notebook Tutorial",
                              size=(600,400)
                              )
            panel = wx.Panel(self)
    
            notebook = wx.Notebook(panel)
            tabOne = TabPanel(notebook)
            notebook.AddPage(tabOne, "Tab 1")
    
            tabTwo = TabPanel(notebook)
            notebook.AddPage(tabTwo, "Tab 2")
    
            sizer = wx.BoxSizer(wx.VERTICAL)
            sizer.Add(notebook, 1, wx.ALL|wx.EXPAND, 5)
            panel.SetSizer(sizer)
            self.Layout()
    
            self.Show()
    
    if __name__ == "__main__":
        app = wx.App(False)
        frame = DemoFrame()
        app.MainLoop()