J'ai un Panel sur lequel j'affiche un StaticBitmap initialisé avec un identifiant de 2. Lorsque je lie un événement souris à l'image et appelle GetId() sur l'événement, il renvoie -202. Pourquoi?wxPython: ID de fenêtre et d'événement
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id=-1):
wx.Frame.__init__(self,parent,id)
self.panel = wx.Panel(self,wx.ID_ANY)
img = wx.Image("img1.png",wx.BITMAP_TYPE_ANY)
img2 = wx.StaticBitmap(self.panel,2,wx.BitmapFromImage(img))
print img2.GetId() # prints 2
img2.Bind(wx.EVT_LEFT_DOWN,self.OnDClick)
def OnDClick(self, event):
print event.GetId() # prints -202
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyFrame(None)
frame.Show()
app.MainLoop()
Il n'y a pas de problème avec votre code, je l'ai juste couru, votre gestionnaire imprime 2 – volting
@volting: Je l'ai exécuté aussi et vous avez raison. – FogleBird
Quelle plateforme et quelles versions de Python/wxPython? – FogleBird