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

  • Home
  • SEARCH
  • 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 709879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:33:10+00:00 2026-05-14T04:33:10+00:00

I am rather new to wx/python so please excuse if this is stupid or

  • 0

I am rather new to wx/python so please excuse if this is stupid or ill described.

I am substituting a nested sizer with a new one as shown in the snippet below. after some tinkering everything seems to work out but the re-drawing of the parent-sizer.
the content of the old nested sizer remains and gets “painted” over with the new sizer content despite my sizer.Layout()

system setup:
– python 2.5.5.2 and 2.6.4
– wxpython 2.8

# -*- coding: utf8 -*-

import wx

class Frame(wx.Frame):
def __init__(self):
    wx.Frame.__init__(self, None, wx.ID_ANY, title='test')

class Test(wx.App):
    def OnInit(self):
        frame = Frame()
        self.panel = wx.Panel(frame)
        self.panel.SetBackgroundColour('red')
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        button = wx.Button(self.panel, wx.ID_ANY, 'TEST')

        self.hsizer = wx.BoxSizer(wx.HORIZONTAL)
        self.hsizer.Add(wx.StaticText(self.panel, wx.ID_ANY, 'nacknack'))

        self.sizer.Add(button)
        self.Bind(wx.EVT_BUTTON, self.on_test_button, button)
        self.text = wx.StaticText(self.panel, wx.ID_ANY, 'FOOO')
        self.sizer.Add(self.text)
        self.sizer.Add(self.hsizer)
        self.panel.SetSizer(self.sizer)
        frame.Show()
        return True

    def on_test_button(self, evt):
        tmpsizer = wx.BoxSizer(wx.VERTICAL)
        tmpsizer.Add(self.makesizer())
        tmpitem = tmpsizer.GetChildren()[0]

        self.sizer.Replace(2, tmpitem)
        self.sizer.Layout()

    def makesizer(self):
        testsizer = wx.BoxSizer(wx.HORIZONTAL)
        testsizer.Add(wx.StaticText(self.panel, wx.ID_ANY, 'testsizer'))
        return testsizer

    if __name__ == '__main__':
        app = Test()
        app.MainLoop()
  • 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-14T04:33:10+00:00Added an answer on May 14, 2026 at 4:33 am

    After looking through your code (and it wasn’t easy – please consider formatting it differently next time – maybe grouping the self.sizer.add functions or something) I think I discovered your bug:

    When you call Replace on a sizer, the item being replaced is not destroyed but becomes no longer managed by the sizer. You need to hide or destroy the old window (the wx.StaticText)

    As mentioned in the wxWidgets docs:

    virtual bool Replace (wxWindow *oldwin, wxWindow *newwin, bool recursive=false)
        Detaches the given oldwin from the sizer and replaces it with the given newwin.

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

Sidebar

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.