我有一个程序,显示一套卡片作为重叠图像,我希望通过双击选择卡。不幸的是,我编程它的方式,程序选择重叠的图像而不是顶部图像(例如,如果我点击KS,系统打印'AS'等.JS返回QS的区域重叠,但JS右边那个)
这些卡是.png图像72x96像素。
任何人都可以建议我如何设置它以响应显示的卡片?
以下是单张卡片图片
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()
答案 0 :(得分:0)
通过在图像上使用GetSubImage()方法解决
谢谢,如果你看了:))
TextBlock