Reputation: 792
I'm just starting out writing a program with the PyQt5
gui framework. I have a file, resource_loader.py
, which is responsible for loading images etc.
The problem
Python crashes at the line where the image is loaded. I'm using IDLE (3.5) and after I run the program there is no output except for:
=============================== RESTART: Shell ===============================
Code - pretty much copy/pasted from a tutorial, file is called resource_loader.py
from PyQt5 import QtGui
import os
file_image = QtGui.QPixmap("file.png")
Things I've tried
file.png
definitely is in the same directory as resource_loader.py
Changing up the variable names, just in case.
Moving the file to a location with no spaces in the path
Extra information
I am running resource_loader.py
directly
I am using Linux Mint (18.3) Xfce if that's any use.
Thanks in advance.
Upvotes: 1
Views: 206
Reputation: 1435
It is required to place your code within a QApplication
instance as follows:
import sys
import os
from PyQt5 import QtGui
from PyQt5.QtWidgets import (QApplication, QWidget)
app = QApplication(sys.argv)
file_image = QtGui.QPixmap("file.png")
sys.exit(app.exec_())
Upvotes: 2