![]() If it can be displayed normally, it means that this method is very successful and we can share it with friends at will! And you can see our program is executable successful. We can delete all the explode picture in your computer and execute the test_GUI.exe. b64decode ( explode )Īnd we package it again: pyinstaller -F test_GUI.py -noconsole This is another easy way to display our picture.īyte_data = base64. Method-2: using absolution path to load picture You can not move the picture, and the picture need to stay with the executable file. But I have to remind: I do not recommend this way. This time we can execute the program normally. Don’t forget will must named it be test.png. We can use the method 1 to fix it: We copy the explore picture and move it to this folder. This is normal, because the executable file cannot find the picture we want to display. We will get an error message: Failed to execute script test_GUI. We have an executable file test_GUI.exe, double click and run it. (Explain: -F means we package to just only one executable file, –noconsole means we cancel the terminal black window show when we running the executable file) Method-1: Put the picture in the directory of the executable fileįirst we using the Python package PyInstaller to package our program with picture to the executable file. ![]() I use OpenCV module to load the picture ( the picture named test.png), and use QPixmap() to store it, and use the QLabel component to show it.Īt this point, the preparatory work has come to an end. Image = QImage ( image, w, h, bytesPerLine, QImage. If you want to learn about PyQt5 module, may be you can refer my blog article: PyQt5 Tutorial (1) Install PyQt5 and print “Hello World!”įirst, I use Qt Designer (a graphic tool) to create a simple window, there is only a component: QLabel.Ĭlass MainWindow ( QtWidgets. If you want to know how does PyInstall work, may be you can refer my blog article in past: PyInstaller - How to make a exe file from Python file It is still available even if you share it with others On your computer, neither executable files nor pictures can be changed into folders Put the picture in the directory of the executable fileĬonvert the picture to byte and load it in the code We have three methods to solve it, and I will record them in this article. When we used PyInstaller to create a Python program as an executable file, we usually need to display a picture in our program.īut if we used PyInstaller to make an executable file directly, we found we can’t show the picture.
0 Comments
Leave a Reply. |