1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
import wx
import cStringIO
class MyFrame(wx.Frame):
"""create a color frame, inherits from wx.Frame"""
def __init__(self, parent):
# -1 is the default ID
wx.Frame.__init__(self, parent, -1, "Click for mouse position", size=(800,540),
style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE )
#self.SetBackgroundColour('Goldenrod')
imageFile = 'image0.png'
data = open(imageFile, "rb").read()
# convert to a data stream
stream = cStringIO.StringIO(data)
# convert to a bitmap
bmp = wx.BitmapFromImage( wx.ImageFromStream( stream ))
self.Panel0 = wx.Panel(self,size=(80,540),pos=(0,0))
self.Panel = wx.Panel(self,size=(720,540),pos=(80,0))
self.Bitmap = wx.StaticBitmap(self.Panel, -1 ,bmp , pos=(0,0))
wx.EVT_ENTER_WINDOW(self.Panel, self.ChangeCursor)
wx.EVT_LEFT_DOWN(self.Bitmap, self.OnLeftDown)
wx.EVT_RIGHT_DOWN(self.Bitmap, self.OnRightDown)
def ChangeCursor(self, event):
self.Bitmap.SetCursor(wx.StockCursor(wx.CURSOR_BULLSEYE))
def OnLeftDown(self, event):
"""left mouse button is pressed"""
pt = event.GetPosition() # position tuple
print pt
self.SetTitle('LeftMouse = ' + str(pt))
def OnRightDown(self, event):
"""right mouse button is pressed"""
pt = event.GetPosition()
print pt
self.SetTitle('RightMouse = ' + str(pt))
app = wx.PySimpleApp()
frame = MyFrame(None)
frame.Show(True)
app.MainLoop() |
Partager