将图片文件嵌入到wxpython代码中的实现方法
作者:mdxy-dxy 时间:2023-04-23 06:52:20
下面直接上代码留存,方便以后查阅复用。
# -*- 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调用。
程序运行的结果如下:
标签:图片,wxpython
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
利用ASP远程注册DLL的方法
2008-03-05 13:00:00
tensorflow pb to tflite 精度下降详解
2023-05-25 19:05:41
css网页下拉菜单制作方法(1):基本原理
2007-02-03 11:39:00
PyTorch搭建LSTM实现时间序列负荷预测
2023-08-18 09:10:09
![](https://img.aspxhome.com/file/2023/9/76999_0s.png)
selenium切换标签页解决get超时问题的完整代码
2023-08-26 09:41:25
![](https://img.aspxhome.com/file/2023/7/118427_0s.gif)
JS出现404错误原理及解决方案
2024-04-28 09:41:26
![](https://img.aspxhome.com/file/2023/1/132841_0s.png)
谈谈Tempdb对SQL Server性能优化有何影响
2024-01-28 04:55:31
![](https://img.aspxhome.com/file/2023/5/113595_0s.jpg)
一列保存多个ID(将多个用逗号隔开的ID转换成用逗号隔开的名称)
2012-08-21 10:37:37
tensorflow 使用flags定义命令行参数的方法
2021-03-20 10:43:23
对python 操作solr索引数据的实例详解
2023-11-02 16:18:19
![](https://img.aspxhome.com/file/2023/5/77715_0s.jpg)
Python time模块之时间戳与结构化时间的使用
2024-01-02 09:07:51
![](https://img.aspxhome.com/file/2023/3/66383_0s.png)
百分百成功的全网最简约sklearn环境配置教程
2022-03-27 13:43:44
![](https://img.aspxhome.com/file/2023/5/101735_0s.png)
一文搞懂MySQL XA如何实现分布式事务
2024-01-22 23:25:19
![](https://img.aspxhome.com/file/2023/8/121238_0s.png)
python小项目之五子棋游戏
2022-07-12 06:24:23
![](https://img.aspxhome.com/file/2023/8/72848_0s.jpg)
谈切图优化加速图片显示—淘宝实例
2008-01-30 12:24:00
![](https://img.aspxhome.com/file/UploadPic/20081/30/200813012349773s.gif)
详解Mysql数据库平滑扩容解决高并发和大数据量问题
2024-01-19 12:52:13
![](https://img.aspxhome.com/file/2023/1/107921_0s.png)
Python 多进程、多线程效率对比
2022-01-23 00:54:24
关于django连接mysql数据库并进行数据库的创建的问题
2024-01-22 04:50:12
![](https://img.aspxhome.com/file/2023/4/110334_0s.png)
Oracle数据库的十种重新启动步骤
2012-07-21 14:58:25
sqlserver数据库优化解析(图文剖析)
2024-01-17 08:55:37
![](https://img.aspxhome.com/file/2023/8/98008_0s.jpg)