下面直接上代碼留存,方便以后查閱復(fù)用。
# -*- coding: utf-8 -*- #作者:LeniyTsan#時(shí)間:2014-07-17 import wxfrom wx.lib.embeddedimage import PyEmbeddedImage class MyFrame1 ( wx.Frame ): def __init__( self, parent ): wx.Frame.__init__ ( self, parent ) self.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_3DLIGHT ) ) bSizer1 = wx.BoxSizer( wx.VERTICAL ) file = open('author.png', 'rb') b64 = file.read().encode('base64') file.close() bitmap = PyEmbeddedImage(b64).GetBitmap() self.m_bitmap1 = wx.StaticBitmap( self, wx.ID_ANY, bitmap ) bSizer1.Add( self.m_bitmap1, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 ) self.SetSizer( bSizer1 ) self.Layout() bSizer1.Fit( self ) self.Centre( wx.BOTH )app = wx.App()gui = MyFrame1(None)gui.Show()app.MainLoop() 重點(diǎn)部分是bitmap = PyEmbeddedImage(b64).GetBitmap()代碼,其中b64是前面生成的圖片的base64字符串,bitmap就是我們的圖片對(duì)象,可以讓wx.StaticBitmap調(diào)用。
程序運(yùn)行的結(jié)果如下:

新聞熱點(diǎn)
疑難解答
圖片精選