源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

将图片文件嵌入到wxpython代码中的实现方法

  • 时间:2020-04-18 11:47 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:将图片文件嵌入到wxpython代码中的实现方法
下面直接上代码留存,方便以后查阅复用。
# -*- coding: utf-8 -*- 
#作者:LeniyTsan
#时间:2014-07-17
 
import wx
from 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() 
重点部分是bitmap = PyEmbeddedImage(b64).GetBitmap()代码,其中b64是前面生成的图片的base64字符串,bitmap就是我们的图片对象,可以让wx.StaticBitmap调用。 程序运行的结果如下: [img]http://files.jb51.net/file_images/article/201408/2014811221628517.png?2014711221958[/img]
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部