python - wxPython: how to determine source of an event -


I have a panel with many images on it, each of which is bound to the same event handler I Can I determine which image is being clicked from the event handler? I tried to use Event.GetEventObject (), but it returns to the parent panel instead of the image that was clicked.

Here is some sample code:

  import math import wx class MyFrame (wx.Frame): def __init __ (auto, parent, id = -1, title) = "", Position = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE, name = "frame"): wx. Frame .__ init __ (self, parent, id, title, status, size, style, name) self.panel = wx.ScrolledWindow (self, wx.ID_ANY) self.panel.SetScrollbars (1,1,1,1 ) Num = 4 column = 3 rows = integer (math.ceil (number / 3.0)) size = ruler = wx.GridSizer (rows = rows, column = column) file name = [] I in range (number): filenames .append ("img" + str (i) + ".png") for file fn: img = wx.Image (Fn, wx.BITMAP_TYPE_ANY) img2 = wx.BitmapFromImage (img) img3 = wx.StaticBitmap (Self.panel, wx.ID_ANY, Img2) sizer.Add (img3) img3.Bind (wx.EVT_LEFT _DCLICK, self.OnDClick) self.panel.SetSizer (size measureter) self.Fit () OnDClick D EF (self, event): print event.GetEventObject () if __name__ == "__main__": app = wx.PySimpleApp () frame = MyFrame (None) frame.Show () app.MainLoop ()   

To do this in a way it would be like this:

  wx.StaticBitmap (auto, wx.ID_ANY, wx.BitmapFromImage (img), name = "bitmap% s"% counter) / Code>  

and then finally increase the counter, then in the event handler, do something like this:

  widget = event.GetEventObject () Print widget. GetName ()  

It has always worked for me.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -