Let's write a simple application using our GUI library:
- Create a file named hello.py:
import sys
from PySide2.QtWidgets import QApplication, QWidget
app = QApplication(sys.argv)
window = QWidget()
window.resize(400, 400)
window.show()
sys.exit(app.exec_())
- Then run it using the following command:
(qt-venv) $ python hello.py
You will now see a blank window:
Let's go through this file to better understand Qt for Python:
import sys
from PySide2.QtWidgets import QApplication, QWidget
The sys import is from the standard Python library. This is required because we want to get the arguments from the command line when we launch this GUI application script. Then we import QApplication and QWidget from PySide2.QtWidgets.
What is PySide2? It comes from PySide, which is a Python binding for Qt 4. PySide2 is a Python binding for Qt 5. PySide was released...