wxPython重叠图像
wxPython overlapping images
我有一个程序可以将一套纸牌显示为重叠图像,我希望通过双击它来 select 纸牌。不幸的是,按照我的编程方式,程序会拾取重叠的图像而不是顶部图像(例如,如果我单击 KS,系统会打印 'AS' 等。JS returns QS 用于重叠区域,但 JS 位于其右侧)
卡片是 72x96 像素的 .png 图片。
任何人都可以建议我如何设置以响应显示的卡片吗?
这是个人名片图片
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()
通过对图像使用 GetSubImage() 方法解决
谢谢你看了:)
def BuildSuit(self, pnl):
cards=['AS', 'KS', 'QS', 'JS']
suitSizer=wx.GridBagSizer(1, 13)
border = 0
for ii in range(0, len(cards)):
card=cards[ii]
image = wx.Bitmap('Images/CardImages/'+card+'.png',wx.BITMAP_TYPE_PNG).ConvertToImage()
image=image.GetSubImage(wx.Rect(0, 0, 26, 96))
img = wx.StaticBitmap(pnl, -1, image.ConvertToBitmap(), name=card)
img.Bind(wx.EVT_LEFT_DCLICK, self.onSuitClick)
suitSizer.Add(img, pos=(0,ii), flag=wx.LEFT, border=border)
border = -13
return suitSizer
我有一个程序可以将一套纸牌显示为重叠图像,我希望通过双击它来 select 纸牌。不幸的是,按照我的编程方式,程序会拾取重叠的图像而不是顶部图像(例如,如果我单击 KS,系统会打印 'AS' 等。JS returns QS 用于重叠区域,但 JS 位于其右侧)
卡片是 72x96 像素的 .png 图片。
任何人都可以建议我如何设置以响应显示的卡片吗?
这是个人名片图片
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()
通过对图像使用 GetSubImage() 方法解决
谢谢你看了:)
def BuildSuit(self, pnl):
cards=['AS', 'KS', 'QS', 'JS']
suitSizer=wx.GridBagSizer(1, 13)
border = 0
for ii in range(0, len(cards)):
card=cards[ii]
image = wx.Bitmap('Images/CardImages/'+card+'.png',wx.BITMAP_TYPE_PNG).ConvertToImage()
image=image.GetSubImage(wx.Rect(0, 0, 26, 96))
img = wx.StaticBitmap(pnl, -1, image.ConvertToBitmap(), name=card)
img.Bind(wx.EVT_LEFT_DCLICK, self.onSuitClick)
suitSizer.Add(img, pos=(0,ii), flag=wx.LEFT, border=border)
border = -13
return suitSizer