我十分不明白self.ic
應該是(wx.StaticBitmap
實例的列表或wx.Bitmap
實例的列表)。你似乎混淆了兩者。 A StaticBitmap
是wxPython
小部件,wx.Bitmap
就是一個保存位圖數據的數據結構。
見下文一個工作例如:
import wx
class bmpframe(wx.Frame):
def __init__(self, *args, **kwds):
wx.Frame.__init__(self, *args, **kwds)
pnl = wx.Panel(self, -1)
# lazy way to make two discernable bitmaps
# Warning: alpha does not work on every platform/version
bmp1 = wx.EmptyBitmapRGBA(64, 64, alpha=0)
bmp2 = wx.EmptyBitmapRGBA(64, 64, alpha=1)
static_bitmap_1 = wx.StaticBitmap(pnl, -1, bitmap=bmp1)
static_bitmap_2 = wx.StaticBitmap(pnl, -1, bitmap=bmp2)
self.stbmp1 = static_bitmap_1
self.stbmp2 = static_bitmap_2
self.btn_swap = wx.Button(pnl, -1, u'Swap…')
szmain = wx.BoxSizer(wx.VERTICAL)
szmain.Add(static_bitmap_1, 0, wx.EXPAND|wx.ALL, 4)
szmain.Add(static_bitmap_2, 0, wx.EXPAND|wx.ALL, 4)
szmain.Add(self.btn_swap, 0, wx.EXPAND|wx.ALL, 4)
pnl.SetSizer(szmain)
szmain.Fit(self)
self.btn_swap.Bind(wx.EVT_BUTTON, self.on_swap)
def on_swap(self, evt):
print 'EVT_BUTTON'
bmp1 = self.stbmp1.GetBitmap()
bmp2 = self.stbmp2.GetBitmap()
self.stbmp1.SetBitmap(bmp2)
self.stbmp2.SetBitmap(bmp1)
self.Refresh()
if __name__ == '__main__':
app = wx.App(redirect=False)
frm = bmpframe(None, -1, 'testbmpswap')
frm.Show()
app.MainLoop()
你能提供一個小的可運行的例子嗎? – 2015-02-24 15:56:14