Python PyQt5 IMAGES are easy!

69 Views
Published
#pythontutorial #python #pyqt5

# PyQt5 images
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel
from PyQt5.QtGui import QPixmap

class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setGeometry(700, 300, 500, 500)

label = QLabel(self)
label.setGeometry(0, 0, 500, 500)

pixmap = QPixmap("profile_pic.jpg")
label.setPixmap(pixmap)

label.setScaledContents(True)

label.setGeometry((self.width() - label.width()) // 2,
(self.height() - label.height()) // 2,
label.width(),
label.height())

def main():
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())

if __name__ == "__main__":
main()
Category
Bro Code
Tags
Python tutorial, python course, python programming
Be the first to comment