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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:33:55+00:00 2026-06-06T10:33:55+00:00

I have a wx.Frame . I need to change the content from time to

  • 0

I have a wx.Frame. I need to change the content from time to time.
I have a timer and every few seconds I check the state, and if the state has been changed, I need to change the content of the frame.

In order to do this, I created a panel in the frame called panel.Reparent(None), and created a panel with new content, but the frame is not updated with the newly created panel. I tried with destroy (panel.Destroy()) but this didn’t work.

What is the recommended way to change frame content (not only data, I need to add and remove UI components)?

class TestFrame(wx.Frame):
def init(self):
wx.Frame.init(self, None, title=”Double Buffered Drawing”)
self.counter = 0
self.panel = wx.Panel(self, -1)
wx.CheckBox(self.panel, -1, “Alpha”, (35, 40), (150, 20))

    # Create a timer to update the data values
    self.Bind(wx.EVT_TIMER, self.OnTimeout)
    self.timer = wx.Timer(self)
    self.timer.Start(5000)


def OnTimeout(self, evt):
    p  = self.panel
    self.counter = self.counter + 1
    try:
        p.Reparent(None)
    except e:
        print 'B'
    if self.counter % 2 == 0:
       self.panel = wx.Panel(self, -1)
       wx.CheckBox(self.panel, -1, "Alpha", (35, 40), (150, 20))
       self.Show()  #Tried also self.Layout self.Refresh self.Update
  • 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-06-06T10:33:56+00:00Added an answer on June 6, 2026 at 10:33 am

    When adding or removing widgets during run time, you almost always have to call Layout() after the removal or addition of a widget. Usually calling Layout on the parent sizer will do the trick, but sometimes you have to call it on the frame object. You can see one example here where I just hid one panel and showed another.

    I also wrote another tutorial on actually removing or adding widgets dynamically. That might help you too.

    EDIT (6-26-12): Since the OP seems to require an example, I wrote a self-destructing panel:

    import wx
    
    ########################################################################
    class PanelOne(wx.Panel):
        """"""
    
        #----------------------------------------------------------------------
        def __init__(self, parent):
            """Constructor"""
            wx.Panel.__init__(self, parent)
    
            self.countdown = wx.StaticText(self, label="This panel will self-destruct in 10 seconds")
    
    
    ########################################################################
    class PanelTwo(wx.Panel):
        """"""
    
        #----------------------------------------------------------------------
        def __init__(self, parent):
            """Constructor"""
            wx.Panel.__init__(self, parent)
    
            txt = wx.StaticText(self, label="Panel Two")
    
    
    ########################################################################
    class MainFrame(wx.Frame):
        """"""
    
        #----------------------------------------------------------------------
        def __init__(self):
            """Constructor"""
            wx.Frame.__init__(self, None, title="Panel Smacker")
            self.panelOne = PanelOne(self)
            self.time2die = 10
    
            self.timer = wx.Timer(self)
            self.Bind(wx.EVT_TIMER, self.update, self.timer)
            self.timer.Start(1000)
    
            self.sizer = wx.BoxSizer(wx.VERTICAL)
            self.sizer.Add(self.panelOne, 1, wx.EXPAND)
            self.SetSizer(self.sizer)
    
        #----------------------------------------------------------------------
        def update(self, event):
            """"""
            if self.time2die < 0:
                self.panelOne.Destroy()
                self.panelTwo = PanelTwo(self)
                self.sizer.Add(self.panelTwo, 1, wx.EXPAND)
                self.Layout()
                self.timer.Stop()
            else:
                msg = "This panel will self-destruct in %s seconds" % self.time2die
                self.panelOne.countdown.SetLabel(msg)
            self.time2die -= 1
    
    if __name__ == "__main__":
        app = wx.App(False)
        frame = MainFrame()
        frame.Show()
        app.MainLoop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to have multiple time frame on a zedgraph. I have to display
I have a list filter = ['a', 'b', 'c']. I need to frame the
I need my JFrame to have a squared size. In the beginning my frame
I have 4 lines UILabel with exact frame and font. I need to know
I have a Windows Media Video file, and the need to grab a frame
I have a dataframe with distances df<-data.frame(site.x=c(A,A,A,B,B,C), site.y=c(B,C,D,C,D,D),Distance=c(67,57,64,60,67,60)) I need to convert this to
I have a frame extends from JWindow (because I want to handle my X
I have a document which has a nested frameset. I need to access one
Hi I have a grouped tableview and i need to change the padding of
I have a silverlight control that has a Frame on it. I want to

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.