Updating content of sizer

Hello,

I am developing my first gui with wxPython and I have been facing a problem for some time now. I have a GridBagSizer and at some point during the program I change the content of one the positions in it. However, the old content is not removed from the screen. Furthermore, the new item doesn’t even get on the same position as the old one.

There’s a little example below.

Any help is appreciated. Thanks,

Martin

···

import wx

class MyFrame(wx.Frame):

def __init__(self, parent):

    wx.Frame.__init__(self, parent)

    mainSizer = wx.BoxSizer(wx.HORIZONTAL)

    grid = wx.GridBagSizer(hgap=2, vgap=2)

    text1 = wx.StaticText(self, label='Text 1')

    grid.Add(text1, pos=(0,0))

    text2 = wx.StaticText(self, label='Text 2')

    grid.Add(text2, pos=(0,0))

    mainSizer.Add(grid, 0, wx.ALL, 5)

    self.SetSizerAndFit(mainSizer)

    self.Show()

app = wx.App(False)

frame = MyFrame(None)

app.MainLoop()

You need to either Destroy() the old widget, or at least detach it from the sizer and hide it. You should be getting an exception telling you that you can't add an item in the same position as another in the sizer, so I guess you're running on a build that has the runtime assertions turned off...

···

On 10/7/11 8:43 AM, Martin Ichilevici de Oliveira wrote:

Hello,

I am developing my first gui with wxPython and I have been facing a
problem for some time now. I have a GridBagSizer and at some point
during the program I change the content of one the positions in it.
However, the old content is not removed from the screen. Furthermore,
the new item doesn't even get on the same position as the old one.

--
Robin Dunn
Software Craftsman