PyQt4中exe的窗口图标 [英] Window Icon of Exe in PyQt4

查看:66
本文介绍了PyQt4中exe的窗口图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 PyQt4 中有一个小程序,我想把这个程序编译成一个 Exe.我正在使用 py2exe 来做到这一点.我可以使用以下代码在 Windows 标题栏中成功设置图标,但是当我将它编译成 exe 时,图标丢失了,我看到了默认的 Windows 应用程序.这是我的程序:

I have a small program in PyQt4 and I want to compile the program into an Exe. I am using py2exe to do that. I can successfully set icon in the windows title bar using the following code, but when i compile it into exe the icon is lost and i see the default windows application. here is my program:

import sys
from PyQt4 import QtGui


class Icon(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle('Icon')
        self.setWindowIcon(QtGui.QIcon('c:/python26_/repy26/icons/iqor1.ico'))


app = QtGui.QApplication(sys.argv)
icon = Icon()
icon.show()
sys.exit(app.exec_())

**** 这里是py2exe的setup.py****

**** Here is the setup.py for py2exe****

from distutils.core import setup
import py2exe

setup(windows=[{"script":"iconqt.py"
               ,"icon_resources": [(1, "Iqor1.ico")]}]
                   ,options={"py2exe":{"includes":["sip", "PyQt4.QtCore"]}})

推荐答案

问题是 py2exe 不包含 qt 图标阅读器插件.您需要告诉它使用 data_files 参数包含它.一些类似的东西:

The problem is that py2exe doesn't include the qt icon reader plugin. You need to tell it to include it with the data_files parameter. Something along these lines:

setup(windows=[{"script":script_path,
                "icon_resources":[(1, icon_path)]}], 
      data_files = [
            ('imageformats', [
              r'C:\Python26\Lib\site-packages\PyQt4\plugins\imageformats\qico4.dll'
              ])],
      options={"py2exe":{"packages":["gzip"], 
                         "includes":["sip"]}})

这篇关于PyQt4中exe的窗口图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆