Last active
October 9, 2020 11:16
-
-
Save TimSC/cf231ab0e26cb3fe9dc30427159b4bbd to your computer and use it in GitHub Desktop.
Minimal pyside2 application
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
# The code is placed into public domain by anatoly techtonik | |
# Feel free to copy/paste wherever you like | |
# Absolutely minimal example of PySide2 application with window | |
from PySide2 import QtGui, QtWidgets | |
# Get entrypoint through which we control underlying Qt framework | |
app = QtWidgets.QApplication([]) | |
# Qt automatically creates top level application window if you | |
# instruct it to show() any GUI element | |
window = QtWidgets.QLabel('Window from label') | |
window.show() | |
# IMPORTANT: `window` variable now contains a reference to a top | |
# level window, and if you lose the variable, the window will be | |
# destroyed by PySide automatically, e.g. this won't show: | |
# | |
# QLabel('New Window').show() | |
# | |
# This is true for other PySide2 objects, so be careful. | |
# Start Qt/PySide2 application. If we don't show any windows, the | |
# app would just loop at this point without the means to exit | |
app.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment