I have a script which looks at multiple values within a large database, and draws coordinates on a floatcanvas. I also have some thresehold variables attached to a slider widget. As the slider changes the thresehold value, the canvas is redrawn...well...sort of. It draws the new objects over the old, but I can't figure out how to get rid of the old one. I get the error that the object does not have the attribute 'Destroy'. Is there another way to remove/delete an object from a float canvas?

The following isn't the actual code, but illustrates the problem just the same. Thanks again for any suggestions. Cheers.


import wx

app = wx.App(0)

    import sys
    from floatcanvas import NavCanvas, FloatCanvas, GUIMode
except ImportError:
    from wx.lib.floatcanvas import NavCanvas, FloatCanvas, GUIMode

class TestFrame(wx.Frame):
    def __init__(self, *args, **kwargs):

        wx.Frame.__init__(self, *args, **kwargs)
        self.canvas =FloatCanvas.FloatCanvas(self, BackgroundColor = "DARK SLATE BLUE")
        # Layout
        MainSizer = wx.BoxSizer(wx.VERTICAL)
        MainSizer.Add(self.canvas, 4, wx.EXPAND)
        self.canvas.Bind(FloatCanvas.EVT_LEFT_DOWN, self.OnLeftDown)

        self.RectN = self.canvas.AddRectangle((10,10), (100, 20), FillColor="red")        

# Delete rectangle on mouse click
    def OnLeftDown(self, event):
        print 'Left Button clicked at:', event.Coords
frame = TestFrame(None, title="Mouse Event Tester")

Try ...

def OnLeftDown(self, event):
        print 'Left Button clicked at:', event.Coords
        # clear all objects off the canvas
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.