[Image-SIG] Displaying Images and getting input from Mouse

Christopher Barker Chris.Barker at noaa.gov
Sat May 6 00:21:51 CEST 2006


Wynand Singels wrote:
> Or am I missing some part of wxPython that can do this? 

Here you go. I used the wx.lib.GenBitmap, as events are not very robust 
with the standard wx.StaticBitmap.

#!/usr/bin/env python
import wx

import wx.lib.statbmp as statbmp

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

         bmp = wx.Bitmap("Images/medtest.jpg")
         self.Image = statbmp.GenStaticBitmap(self, wx.ID_ANY, bmp)

         self.Image.Bind(wx.EVT_LEFT_DOWN, self.OnClick)

         S = wx.BoxSizer(wx.VERTICAL)
         S.Add(self.Image, 0)
         self.SetSizerAndFit(S)

     def OnClick(self, event):
         print "Image: was clicked at: %i, %i "%(event.GetX(), event.GetY())

class App(wx.App):
     def OnInit(self):
         frame = MainFrame(None, title= "wxWindowBitmap Test")
         self.SetTopWindow(frame)
         frame.Show(True)
         return True

app = App(0)
app.MainLoop()


-Chris



-- 
Christopher Barker, Ph.D.
Oceanographer
                                     		
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov


More information about the Image-SIG mailing list