I have a program that displays a suit of cards as overlapped images and I wish to select card by double clicking on it. Unfortunately, the way I've programmed it, the program pick up the image that has been overlapped and not the top image (e.g, if I click on KS, the system prints 'AS' etc. The JS returns QS for the area of the overlap, but JS to the right of that)
The cards are .png images 72x96 pixels.
Can anyone please suggest how I can set it up to respond to the displayed card?
Here are the individual card images
import wx
class Example(wx.Frame):
def __init__(self, parent, title):
super(Example, self).__init__(parent, title=title,
size=(250, 200))
self.Center()
self.Show()
pnl = wx.Panel(self)
mainSizer= self.BuildSuit(pnl)
pnl.SetSizer(mainSizer)
pnl.Layout()
pnl.Fit()
def BuildSuit(self, pnl):
cards=['AS', 'KS', 'QS', 'JS']
suitSizer=wx.GridBagSizer(1, 13)
border = 10
for ii in range(0, len(cards)):
card=cards[ii]
image = wx.Bitmap('Images/CardImages/'+card+'.png',wx.BITMAP_TYPE_PNG)
img = wx.StaticBitmap(pnl, -1, image, name=card)
img.Bind(wx.EVT_LEFT_DCLICK, self.onSuitClick)
suitSizer.Add(img, pos=(0,ii), flag=wx.LEFT, border=border)
border = -50
return suitSizer
def onSuitClick(self, event):
imgCtrl=event.GetEventObject()
print imgCtrl.GetName()
if __name__ == '__main__':
app = wx.App()
Example(None, title='Double click images')
app.MainLoop()
Solved by using the GetSubImage() method on an image
Thanks if you looked :)