Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7060867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:24:16+00:00 2026-05-28T04:24:16+00:00

import wx import wx.grid as gridlib ######################################################################## class PanelOne(wx.Panel): #———————————————————————- def __init__(self, parent): Constructor

  • 0
import wx
import wx.grid as gridlib

########################################################################
class PanelOne(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent=parent)
        txt = wx.TextCtrl(self)
        button =wx.Button(self, label="Save", pos=(200, 325))
        button.Bind(wx.EVT_BUTTON, self.onSwitchPanels)

########################################################################
class PanelTwo(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent=parent)

        grid = gridlib.Grid(self)
        grid.CreateGrid(25,12)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(grid, 0, wx.EXPAND)
        self.SetSizer(sizer)

########################################################################
class MyForm(wx.Frame):

    #----------------------------------------------------------------------
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY,
                          "Panel Switcher Tutorial")

        self.panel_one = PanelOne(self)
        self.panel_two = PanelTwo(self)
        self.panel_two.Hide()

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.panel_one, 1, wx.EXPAND)
        self.sizer.Add(self.panel_two, 1, wx.EXPAND)
        self.SetSizer(self.sizer)

        menubar = wx.MenuBar()
        fileMenu = wx.Menu()
        switch_panels_menu_item = fileMenu.Append(wx.ID_ANY,
                                                  "Switch Panels",
                                                  "Some text")
        self.Bind(wx.EVT_MENU, self.onSwitchPanels,
                  switch_panels_menu_item)
        menubar.Append(fileMenu, '&File')
        self.SetMenuBar(menubar)

    #----------------------------------------------------------------------
    def onSwitchPanels(self, event):

       if self.panel_one.IsShown():    
          self.SetTitle("Panel Two Showing")
          self.panel_one.Hide
          self.panel_two.Show()
       else:
          self.SetTitle("Panel One Showing")
          self.panel_one.Show()
          self.panel_two.Hide()
          self.Layout()


# Run the program
if __name__ == "__main__":
    app = wx.App(False)
    frame = MyForm()
    frame.Show()
    app.MainLoop()

I want to call function onSwitchPanels when i click the button in class PanelOne.This application i want to work like this code in Tkinter.

I have stack guys, help me and thanks a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:24:17+00:00Added an answer on May 28, 2026 at 4:24 am

    I wrote a tutorial on this subject over a year ago, although I use a menu to do the switching. You can adjust the code to make your button do it though. Here’s the tutorial: http://www.blog.pythonlibrary.org/2010/06/16/wxpython-how-to-switch-between-panels/

    EDIT: The problem with the code above is three-fold. First in the onSwitchPanels method, you need to have “self.panel_one.Hide()”. Note the parentheses that are missing in your code. Secondly, you really need to have the “self.Layout()” un-indented so it’s on the same level as the if statement, NOT inside the “else” part. Lastly, you can’t call “onSwitchPanels” from PanelOne because it’s not defined there. You can change it so it’s like this though:

    button.Bind(wx.EVT_BUTTON, parent.onSwitchPanels)
    

    Ugly and not really recommended, but it works. You should use PubSub for that instead though.

    EDIT #2: Guess I should have just posted the code since the OP won’t even try my suggestions.

    import wx
    import wx.grid as gridlib
    
    ########################################################################
    class PanelOne(wx.Panel):
        """"""
    
        #----------------------------------------------------------------------
        def __init__(self, parent):
            """Constructor"""
            wx.Panel.__init__(self, parent=parent)
            txt = wx.TextCtrl(self)
            button =wx.Button(self, label="Save", pos=(200, 325))
            button.Bind(wx.EVT_BUTTON, parent.onSwitchPanels)
    
    ########################################################################
    class PanelTwo(wx.Panel):
        """"""
    
        #----------------------------------------------------------------------
        def __init__(self, parent):
            """Constructor"""
            wx.Panel.__init__(self, parent=parent)
    
            grid = gridlib.Grid(self)
            grid.CreateGrid(25,12)
    
            sizer = wx.BoxSizer(wx.VERTICAL)
            sizer.Add(grid, 0, wx.EXPAND)
            self.SetSizer(sizer)
    
    ########################################################################
    class MyForm(wx.Frame):
    
        #----------------------------------------------------------------------
        def __init__(self):
            wx.Frame.__init__(self, None, wx.ID_ANY,
                              "Panel Switcher Tutorial",
                              size=(800,600))
    
            self.panel_one = PanelOne(self)
            self.panel_two = PanelTwo(self)
            self.panel_two.Hide()
    
            self.sizer = wx.BoxSizer(wx.VERTICAL)
            self.sizer.Add(self.panel_one, 1, wx.EXPAND)
            self.sizer.Add(self.panel_two, 1, wx.EXPAND)
            self.SetSizer(self.sizer)
    
            menubar = wx.MenuBar()
            fileMenu = wx.Menu()
            switch_panels_menu_item = fileMenu.Append(wx.ID_ANY,
                                                      "Switch Panels",
                                                      "Some text")
            self.Bind(wx.EVT_MENU, self.onSwitchPanels,
                      switch_panels_menu_item)
            menubar.Append(fileMenu, '&File')
            self.SetMenuBar(menubar)
    
        #----------------------------------------------------------------------
        def onSwitchPanels(self, event):
    
            if self.panel_one.IsShown():
               self.SetTitle("Panel Two Showing")
               self.panel_one.Hide()
               self.panel_two.Show()
            else:
               self.SetTitle("Panel One Showing")
               self.panel_one.Show()
               self.panel_two.Hide()
            self.Layout()
    
    # Run the program
    if __name__ == "__main__":
        app = wx.App(False)
        frame = MyForm()
        frame.Show()
        app.MainLoop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

from TKinter import * class Ui(Frame): def __init__(self) Frame.__init__(self, None) self.grid() bquit=Button(self, text=Quit, command=self.quit_pressed)
import wx class MainFrame(wx.Frame): def __init__(self,parent,title): wx.Frame.__init__(self, parent, title=title, size=(640,480)) self.mainPanel=DoubleBufferTest(self,-1) self.Show(True) class DoubleBufferTest(wx.Panel):
import java.lang.Math; public class NewtonIteration { public static void main(String[] args) { System.out.print(rootNofX(2,9)); }
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class DateDemo { public static void main(String[]
import java.io.*; import java.util.Scanner; import java.util.StringTokenizer; public class Filereader { public static void main(String[]
import java.lang.reflect.Array; public class PrimitiveArrayGeneric { static <T> T[] genericArrayNewInstance(Class<T> componentType) { return (T[])
import math def p(n): return 393000*((288200/393000)^n * math.exp(-(288200/393000)))/math.factorial(n) print p(3) When I run it,
I'm using struts2-jquery grid. gridmodel in my action class is getting updated correctly. But,
I have the following class that extends AdvancedDataGridItemRenderer: package { import mx.controls.advancedDataGridClasses.AdvancedDataGridItemRenderer; public class
I have the following code. Class KochSnowflakesMenu is a grid JPanel with three buttons.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.