Jachdich
Jachdich

Reputation: 792

PyQt5 crashes whilst trying to load an PNG image

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

Extra information

Thanks in advance.

Upvotes: 1

Views: 206

Answers (1)

Omari Celestine
Omari Celestine

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

Related Questions