I want to check if bitmap button exists and if exists, then destroy it and if it don´t exists, then create it. This is code:
try:
shutdownbtn
except NameError:
sbex = False
else:
sbex = True
if sbex:
self.shutdownbtn.Destroy()
print "Destroyed"
if not sbex:
self.shutdownbtn = wx.Bitmap("bin/Images/wstdwn.png")
self.wstdwnbtn = wx.StaticBitmap(self, -1, self.shutdownbtn)
self.wstdwnbtn.SetPosition((0, 550))
self.wstdwnbtn.Bind(wx.EVT_LEFT_DOWN, self.wexit)
self.wstdwnbtn.SetToolTip(wx.ToolTip("Exit to main menu."))
It creates the bitmap button, but doesn't delete it! Why? I really don't know.
This is because you're using shutdownbtn
not self.shutdownbtn
. You will also have to catch an AttributeError
, not a NameError
.