Created
May 31, 2018 18:16
-
-
Save omiq/4aa1ea325a9c28d66f76cd442ea8e9f5 to your computer and use it in GitHub Desktop.
example of Python PySide2 Qt viewing an image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PySide2.QtWidgets import* | |
from PySide2.QtGui import* | |
from PySide2 import QtCore | |
# example event handler | |
def quit_app(): | |
global application | |
print("Quit!") | |
application.exit() | |
# base application object for our app | |
application = QApplication(sys.argv) | |
# Create a Window | |
window = QWidget() | |
window.setWindowTitle("View Image") | |
# button | |
button = QPushButton("Quit", window) | |
# on click handler | |
button.clicked.connect(quit_app) | |
# Load Pic | |
picture = QPixmap("background.png") | |
# set up the label widget to display the pic | |
label = QLabel(window) | |
label.setPixmap(picture) | |
label.setGeometry(QtCore.QRect(10, 40, picture.width(), picture.height())) | |
# embiggen the window to correctly fit the pic | |
window.resize(picture.width()+20, picture.height()+100) | |
window.show() | |
# Let QT do its thing | |
sys.exit(application.exec_()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment