我正在尝试将位图与 wxpython 一起使用
在 main.py 中我有:
imag=wx.Image("picture.bmp",wx.BITMAP_TYPE_BMP).ConvertToBitmap()
picture.bmp 与 main.py 在同一文件夹中, 该程序在 IDE 中运行时有效
当我制作exe时它不起作用。
当我运行 cx_freeze 创建的 exe 时,我会弹出一个 cmd 框并显示以下内容:
wxBitmap CreatefromImage(): invalid image
最佳答案
使用此方法
import imp
import os
import sys
def main_is_frozen():
return (hasattr(sys, "frozen") or # new py2exe
hasattr(sys, "importers") # old py2exe
or imp.is_frozen("__main__")) # tools/freeze
def get_main_dir():
if main_is_frozen():
return os.path.dirname(sys.executable)
return os.path.dirname(sys.argv[0])
并使用此代码获取图像路径
imag=wx.Image(get_main_dir()+"/picture.bmp",wx.BITMAP_TYPE_BMP).ConvertToBitmap()
关于python - cx 使用 wxpython 卡住,使用 exe 添加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9575349/