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 7458681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:28:48+00:00 2026-05-29T13:28:48+00:00

I am trying to make a Frame to which we add dynamically panels. Also

  • 0

I am trying to make a Frame to which we add dynamically panels.
Also I also want to remove panel dynamically . The dynamic Addition is working perfect.The removal part is not working at all.
Please see the code below:

# panels.py
#self.Fit() causes the whole frame to shrink.So we are using self.Layout instead

import wx


class Panels(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)

        self.vbox = wx.BoxSizer(wx.VERTICAL)
        panel = wx.Panel(self,-1)
        hbox= wx.BoxSizer(wx.HORIZONTAL)
        b1 = wx.Button(panel, -1, 'Add')
        b2 = wx.Button(panel, -1, 'Remove')
        hbox.Add(b1,-1,wx.ALL,10)
        hbox.Add(b2,-1,wx.ALL,10)
        panel.SetSizer(hbox)

        panel2 = wx.Panel(self,-1)
        hbox2= wx.BoxSizer(wx.HORIZONTAL)
        b1_2 = wx.Button(panel2, -1, 'Button 3')
        b2_2 = wx.Button(panel2, -1, 'Button 4')
        hbox2.Add(b1_2,-1,wx.ALL,10)
        hbox2.Add(b2_2,-1,wx.ALL,10)
        panel2.SetSizer(hbox2)
        self.vbox.Add(panel,-1,wx.EXPAND,10)
        self.vbox.Add((-1, 10))
        self.vbox.Add(panel2,-1,wx.EXPAND,10)


        self.SetSizer(self.vbox)
        self.Layout()
        self.Bind(wx.EVT_BUTTON,self.tst, b1)
        self.Bind(wx.EVT_BUTTON,self.remove, b2)

        self.Centre()

        self.Show(True)

    def tst(self,event):
        self.panel3 = wx.Panel(self,-1)
        hbox3= wx.BoxSizer(wx.HORIZONTAL)
        b1_3 = wx.Button(self.panel3, -1, 'Button 5')
        b2_3 = wx.Button(self.panel3, -1, 'Button 6')
        hbox3.Add(b1_3,-1,wx.ALL,10)
        hbox3.Add(b2_3,-1,wx.ALL,10)
        self.panel3.SetSizer(hbox3)
        self.vbox.Add((-1, 10))
        self.vbox.Add(self.panel3,-1,wx.EXPAND,10)
        self.SetSizer(self.vbox)
        self.Layout()
        return

    def remove(self,event):


        self.vbox.Remove(self.panel3)
        self.SetSizer(self.vbox)
        self.Layout()
        return




app = wx.App()
Panels(None, -1, 'Panels')
app.MainLoop()

Anyone has any suggestions how this can work? I am not sure if ‘.Remove()’ is there at all….Or if it works with panels……

  • 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-29T13:28:49+00:00Added an answer on May 29, 2026 at 1:28 pm

    Depending on what you want to do, you can use the sizer’s Remove or Detach method. Remove will remove the panel and then Destroy it. Detach will basically hide the panel and then you can reuse it. You could use Hide() instead of Detach() for that. If you see a flicker when destroying and creating, you’ll want to look into the Freeze/Thaw methods.

    Finally, I wrote a little article showing how to switch between panels that might help you too: http://www.blog.pythonlibrary.org/2010/06/16/wxpython-how-to-switch-between-panels/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a Frame from which I want to add an image
Trying to make a make generic select control that I can dynamically add elements
trying to make a page which will recursively call a function until a limit
I'm trying make a static text which if too long for the sizer, will
I am trying to make a iPad application which information will popup inside the
I'm trying to make 'dynamic' listview that contains 0-2 headers and 0-1 footer(based on
I am trying to setup a simple function which will make it a lot
So I have been given a C program, which I am trying to make
I am trying to make a simple 3D application in WebGl, in which every
I am trying create a data.frame from which to create a graph. I have

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.