1. Sample code of a simple application
[code lang="python"]import sys
from PySide6.QtWidgets import QApplication, QWidget
# Create an object that represents the app
app = QApplication(sys.argv)
# create main window using QWidget
window = QWidget()
window.setWindowTitle("My first pyside6 window") # đặt tiêu đề
window.resize(400, 300) # đặt kích thước
# Command Show window
window.show()
# Put the app into the event loop to call it to run continuously
sys.exit(app.exec())
[/code]
from PySide6.QtWidgets import QApplication, QWidget
# Create an object that represents the app
app = QApplication(sys.argv)
# create main window using QWidget
window = QWidget()
window.setWindowTitle("My first pyside6 window") # đặt tiêu đề
window.resize(400, 300) # đặt kích thước
# Command Show window
window.show()
# Put the app into the event loop to call it to run continuously
sys.exit(app.exec())
[/code]
Result
2. Explain the components
QApplication is an instance for the entire app that manages the events loopQWidget: represents UI elements (windows, buttons, ...)
sys.exit() : is a built-in function for safe exit in Pythonapp.exec(): execute loop calling app