简体   繁体   English

缺少PyQt图标?

[英]PyQt icons missing?

I am new to PyQt and I am learning to make GUIs based on online tutorials I found. 我是PyQt的新手,我正在学习根据发现的在线教程制作GUI。 One of the examples in the tutorials uses an icon, here is the code from the tutorial: 教程中的示例之一使用一个图标,这是教程中的代码:

import sys
from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication
from PyQt5.QtGui import QIcon

class Example(QMainWindow):

    def __init__(self):
        super().__init__()

        self.initUI()


    def initUI(self):               

        exitAct = QAction(QIcon('exit24.png'), 'Exit', self)
        exitAct.setShortcut('Ctrl+Q')
        exitAct.triggered.connect(qApp.quit)

        self.toolbar = self.addToolBar('Exit')
        self.toolbar.addAction(exitAct)

        self.setGeometry(300, 300, 300, 200)
        self.setWindowTitle('Toolbar')    
        self.show()


if __name__ == '__main__':

    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

The output according to the tutorial should be 根据教程的输出应为

在此处输入图片说明 But for me it's this 但是对我来说就是这个

在此处输入图片说明 As I said, I just started with PyQt and I just installed PyQt through pip 就像我说的,我刚开始使用PyQt并通过pip安装了PyQt

pip install PyQt5

I'm using Python3.6 and PyQt5. 我正在使用Python3.6和PyQt5。 Any help is greatly appreciated! 任何帮助是极大的赞赏!

Yes, PyQt5 does come with a list of default icons. 是的,PyQt5确实带有默认图标列表。 You can find them here: List of PyQt Icons 您可以在这里找到它们: PyQt图标列表

However, it seems the "exit" icon from the tutorial you refrenced used a local icon downloaded on their computer. 但是,您所参考的教程中的“退出”图标似乎使用了在其计算机上下载的本地图标。 You need to download the same icon and name it 'exit24.png' next to your python file. 您需要下载相同的图标,并在python文件旁边将其命名为“ exit24.png”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM