qinhong_lai | 2020-05-28 06:06:06 UTC | #1
Thank you. You have successfully solved this problem and obtained the file path and name. Now I have another problem
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout
from PyQt5.QtGui import *
import sys
class Window(QWidget):
def __init__(self):
super().__init__()
layout = QVBoxLayout()
for arg in sys.argv: # <1> sys.argv is a list of strings.
l = QLabel(arg)
layout.addWidget(l)
self.setWindowIcon(QIcon('resource/logo.ico'))
self.setLayout(layout)
self.setWindowTitle("Arguments")
app = QApplication(sys.argv)
w = Window()
w.show()
app.exec_()
I want to add a program icon self.setWindowIcon(QIcon('resource/logo.ico')) It can be displayed normally
But I use pyinstaller to package and generate exe pyinstaller -w test20.py
When the .MP4 video file on the desktop of the computer is opened through test20.exe, it will not be normal displayed. That's why I can only copy one picture to the desktop,This is not the way to do it
martin | 2020-05-28 08:24:13 UTC | #2
Ah, that's interesting -- you when you run it as a packaged app, the exe file is the first argument? That's kind of helpful. In that case you can just use sys.argv[1]
or get the last argument in the list, e.g.
Purchasing Power Parity
Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]mp4_filename = sys.argv[-1]
That’s why I can only copy one picture to the desktop,This is not the way to do it
I'm not sure what you mean here?
Are you having problems setting the icon for the executable? In the PyInstaller tutorial https://www.pythonguis.com/courses/packaging-and-distribution/packaging-pyqt5-pyside2-applications-windows-pyinstaller/ it explains the problem -- add the following to the top of your file.
from PyQt5.QtWinExtras import QtWin
myappid = 'com.qinhong.something'
QtWin.setCurrentProcessExplicitAppUserModelID(myappid)
and the icon should work as expected.
That tutorial also explains how to bundle the icons with your app.
PyQt6 Crash Course — a new tutorial in your Inbox every day
Beginner-focused crash course explaining the basics with hands-on examples.