在wxPython中,有几个内置的脚本工具可以用来做图片格式转换,在c:\Python26\Lib\site-packages\wx-2.8-msw-unicode\wx\tools\路径下,包括img2png.py、img2py.py、img2xpm.py。
可以使用这些脚本方便地转换图片,如以下两个命令,分别转换图片为.png格式和.xpm格式:
img2png.py <img_files...> img2xpm.py <img_files...>
而img2py.py则可以将图片转换为内嵌于Python脚本的形式:
img2py.py -n AppIcon appname.icon images.py img2py.py -n AppIcon2 -a appname2.icon images.py
第二条命令可以将appname2.icon生成的内嵌文本加在images.py文件中。
然后,就可以在Frame中设置图标了:
import images.py class AppnameFrame(wx.Frame): def __init__(self, parent): wx.Frame.__init__(self, parent, -1, 'Appname', size=(600, 400)) self.SetIcon(images.AppIcon.GetIcon()) # ...
使用内嵌图标的好处是图标包含在程序文本中,通过编译可以实现隐蔽性。