Skip to content

Instantly share code, notes, and snippets.

@TimSC
Last active October 9, 2020 11:16
Show Gist options
  • Save TimSC/cf231ab0e26cb3fe9dc30427159b4bbd to your computer and use it in GitHub Desktop.
Save TimSC/cf231ab0e26cb3fe9dc30427159b4bbd to your computer and use it in GitHub Desktop.
Minimal pyside2 application
# 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