### Run PySide6 Example on Windows Source: https://github.com/erriez/pyside6-getting-started/blob/main/SETUP_WINDOWS.md Activate the virtual environment and run a PySide6 example script. ```bash > venv\Scripts\activate.bat (venv) > python 01_gettings_started\01_simple_example.py ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/erriez/pyside6-getting-started/blob/main/SETUP_WINDOWS.md Clone the PySide6 getting started repository, install virtualenv, create and activate a virtual environment, and install project dependencies. ```bash > git clone https://github.com/Erriez/pyside6-getting-started.git > cd pyside6-getting-started > pip install virtualenv > virtualenv venv > venv\Scripts\activate.bat (venv) > pip install -r requirements.txt ``` -------------------------------- ### Build and Install PySide6 App on Windows Source: https://github.com/erriez/pyside6-getting-started/blob/main/18_deployment/README.md Follow these steps to build the executable and .exe installer for a PySide6 application on Windows using NSIS. Installation is done via the generated setup executable. ```batch # Build executable and installer > build_windows.bat # Run setup > 01_deployment_setup.exe # Uninstall: Via Windows Start Menu or Settings | Apps ``` -------------------------------- ### Run PySide6 Example on Linux Source: https://github.com/erriez/pyside6-getting-started/blob/main/SETUP_LINUX.md Activate the Python virtual environment and execute a PySide6 example script. ```bash # Activate virtual environment $ . venv/bin/activate # Run an example (venv) $ python 01_gettings_started/01_simple_example.py ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/erriez/pyside6-getting-started/blob/main/SETUP_LINUX.md Clone the PySide6 getting started repository and install necessary dependencies using pip within a virtual environment. ```bash # Clone the sources (Make sure git is installed) $ git clone https://github.com/Erriez/pyside6-getting-started.git # Change directory to the sources $ cd pyside6-getting-started # Create a Python virtual environment $ virtualenv venv # Activate virtual environment (Prompt changes to venv) $ . venv/bin/activate # Install dependencies including PySide6 (venv) $ pip install -r requirements.txt ``` -------------------------------- ### Build and Install PySide6 App on Linux Source: https://github.com/erriez/pyside6-getting-started/blob/main/18_deployment/README.md Use these commands to build the executable and .deb installer for a PySide6 application on Linux, then run the installer and the uninstall script. ```bash # Build executable and installer $ ./build_linux.sh # Run setup $ ./pyside6_deployment_example.deb # Uninstall $ $HOME/.local/bin/erriez/pyside6_deployment_example/uninstall.sh ``` -------------------------------- ### Install PySide6 using pip Source: https://github.com/erriez/pyside6-getting-started/blob/main/SETUP_VSCode.md Install the PySide6 library within your activated virtual environment using pip. Ensure the installation completes before proceeding. ```bash pip install PySide6 ``` -------------------------------- ### Create a Wizard Dialog for Multi-Step Forms with QWizard Source: https://context7.com/erriez/pyside6-getting-started/llms.txt Use QWizard and QWizardPage to build guided, multi-step dialogs. Each step is represented by a QWizardPage instance. ```python from PySide6.QtWidgets import QApplication, QFormLayout, QLabel, QLineEdit, QVBoxLayout, QWizardPage, QWizard import sys def create_intro_page(): page = QWizardPage() page.setTitle("Introduction") label = QLabel("This wizard will help you register your copy of Super Product Two.") label.setWordWrap(True) layout = QVBoxLayout(page) layout.addWidget(label) return page def create_registration_page(): page = QWizardPage() page.setTitle("Registration") page.setSubTitle("Please fill both fields.") layout = QFormLayout(page) layout.addRow("Name:", QLineEdit()) layout.addRow("Email address:", QLineEdit()) return page def create_conclusion_page(): page = QWizardPage() page.setTitle("Conclusion") label = QLabel("You are now successfully registered. Have a nice day!") label.setWordWrap(True) layout = QVBoxLayout(page) layout.addWidget(label) return page def main(): QApplication(sys.argv) wizard = QWizard() wizard.addPage(create_intro_page()) wizard.addPage(create_registration_page()) wizard.addPage(create_conclusion_page()) wizard.setWindowTitle("Trivial Wizard") wizard.show() sys.exit(wizard.exec()) if __name__ == '__main__': main() ``` -------------------------------- ### PySide6 Main Window with Menu, Toolbar, and Status Bar Source: https://context7.com/erriez/pyside6-getting-started/llms.txt QMainWindow provides a framework for applications with menus, toolbars, and status bars. QAction defines menu items that can be shared. This example sets up a basic main window with an exit action. ```python from PySide6.QtWidgets import QApplication, QMainWindow, QTextEdit from PySide6.QtGui import QAction, QIcon from pathlib import Path import os import sys class Window(QMainWindow): def __init__(self): super().__init__() self.resize(300, 250) self.setWindowTitle('Main window') # Central widget text_edit = QTextEdit() self.setCentralWidget(text_edit) # Create action with icon, shortcut, status tip, and click handler path = Path(__file__).resolve().parent exit_action = QAction(QIcon(os.path.join(path, '../images/exit.png')), '&Exit', self) exit_action.setShortcut('Ctrl+Q') exit_action.setStatusTip('Exit application') exit_action.triggered.connect(self.close) # Create menubar and add File menu menubar = self.menuBar() menu_file = menubar.addMenu('&File') menu_file.addAction(exit_action) # Create toolbar and add same action toolbar = self.addToolBar('Exit') toolbar.addAction(exit_action) # Create statusbar self.statusBar() def main(): app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec()) if __name__ == '__main__': main() ``` -------------------------------- ### PySide6 Grid Layout for Calculator Interface Source: https://context7.com/erriez/pyside6-getting-started/llms.txt QGridLayout arranges widgets in a grid of rows and columns. Use addWidget(widget, row, column) to place widgets at specific positions. This example creates a calculator-style button layout. ```python from PySide6.QtWidgets import QApplication, QWidget, QGridLayout, QLabel, QPushButton import sys class Window(QWidget): def __init__(self): super().__init__() self.setWindowTitle('Calculator') # Create grid layout grid = QGridLayout() # Define button labels in order button_names = ['Cls', 'Bck', '', 'Close', '7', '8', '9', '/', '4', '5', '6', '*', '1', '2', '3', '-', '0', '.', '=', '+'] # Create and add buttons to grid for i in range(len(button_names)): row = i // 4 col = i % 4 if not button_names[i]: grid.addWidget(QLabel(''), row, col) else: button = QPushButton(button_names[i]) grid.addWidget(button, row, col) self.setLayout(grid) def main(): app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec()) if __name__ == '__main__': main() ``` -------------------------------- ### PySide6 Horizontal and Vertical Box Layouts Source: https://context7.com/erriez/pyside6-getting-started/llms.txt Use QHBoxLayout and QVBoxLayout to arrange widgets horizontally and vertically. addStretch() pushes widgets to specific positions, and addLayout() nests layouts. This example demonstrates aligning buttons to the right and the layout to the bottom. ```python from PySide6.QtWidgets import QApplication, QWidget, QHBoxLayout, QVBoxLayout, QPushButton import sys class Window(QWidget): def __init__(self): super().__init__() self.resize(250, 150) self.setWindowTitle('Buttons') # Create two buttons button_ok = QPushButton("OK") button_cancel = QPushButton("Cancel") # Horizontal layout with stretch to align buttons right hbox = QHBoxLayout() hbox.addStretch(1) # Push buttons to the right hbox.addWidget(button_ok) hbox.addWidget(button_cancel) # Vertical layout with stretch to align at bottom vbox = QVBoxLayout() vbox.addStretch(1) # Push horizontal layout to bottom vbox.addLayout(hbox) self.setLayout(vbox) def main(): app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec()) if __name__ == '__main__': main() ``` -------------------------------- ### Create a System Tray Icon in PySide6 Source: https://context7.com/erriez/pyside6-getting-started/llms.txt Use QSystemTrayIcon to add an icon to the system tray with context menu support. Set setQuitOnLastWindowClosed(False) to ensure the application continues running even after windows are closed. The example includes a basic 'Quit' action in the context menu. ```python from PySide6.QtWidgets import QApplication, QSystemTrayIcon, QMenu from PySide6.QtGui import QIcon, QAction from pathlib import Path import os import sys def main(): app = QApplication(sys.argv) # Keep app running when windows closed app.setQuitOnLastWindowClosed(False) path = Path(__file__).resolve().parent app.setWindowIcon(QIcon(os.path.join(path, "../images/web.png"))) # Create context menu menu = QMenu() btn_quit = QAction('Quit') btn_quit.triggered.connect(QApplication.quit) menu.addAction(btn_quit) # Create and configure system tray icon system_tray = QSystemTrayIcon() system_tray.setIcon(QIcon(os.path.join(path, "../images/web.png"))) system_tray.setVisible(True) system_tray.setContextMenu(menu) system_tray.show() sys.exit(app.exec()) if __name__ == '__main__': main() ``` -------------------------------- ### Custom Drawing with QPainter in PySide6 Source: https://context7.com/erriez/pyside6-getting-started/llms.txt Perform custom drawing by overriding the paintEvent method. Utilize QPainter to draw text, shapes, and images with specified colors and fonts. The example draws centered text onto the widget. ```python from PySide6.QtWidgets import QApplication, QWidget from PySide6.QtGui import QPainter, QColor, QFont from PySide6.QtCore import Qt import sys class Window(QWidget): def __init__(self): super().__init__() self.resize(250, 150) self.setWindowTitle('Draw text') self.text = 'Hello world\nfrom PySide6!' def paintEvent(self, event): # Create painter and draw qp = QPainter() qp.begin(self) self.drawText(event, qp) qp.end() def drawText(self, event, qp): # Set pen color and font qp.setPen(QColor(168, 34, 3)) qp.setFont(QFont('Decorative', 16)) # Draw centered text qp.drawText(event.rect(), Qt.AlignCenter, self.text) def main(): app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec()) if __name__ == '__main__': main() ``` -------------------------------- ### Create a Simple Window with QWidget Source: https://context7.com/erriez/pyside6-getting-started/llms.txt Demonstrates the basic structure of a PySide6 application by creating a simple window. Requires instantiation of QApplication, creation and configuration of a QWidget, showing the widget, and entering the event loop. ```python from PySide6.QtWidgets import QApplication, QWidget import sys def main(): # Create QApplication object - required for any Qt GUI app app = QApplication(sys.argv) # Create QWidget object as the main window window = QWidget() # Configure window properties window.resize(300, 200) window.setWindowTitle('Simple Window') # Show window on screen window.show() # Start application event loop and exit with return code sys.exit(app.exec()) if __name__ == '__main__': main() ``` -------------------------------- ### Manage Application Settings with QSettings Source: https://context7.com/erriez/pyside6-getting-started/llms.txt QSettings allows for persistent storage of application settings across sessions. It uses platform-specific locations for storage. ```python from PySide6.QtWidgets import QApplication, QMainWindow, QLabel from PySide6.QtCore import Qt, QCoreApplication, QPoint, QSize, QSettings import sys ORGANIZATION_NAME = "MyCompany" APPLICATION_NAME = "MyApp" class MainWindow(QMainWindow): def __init__(self): super().__init__() # Load settings settings = QSettings() # Restore window geometry with defaults self.resize(settings.value("window-size", QSize(400, 300))) self.move(settings.value("window-position", QPoint(100, 100))) self.setWindowTitle(settings.value("window-title", APPLICATION_NAME)) self.label = QLabel("Settings are saved on exit", self) self.label.setAlignment(Qt.AlignCenter) self.setCentralWidget(self.label) def closeEvent(self, event): # Save settings before closing settings = QSettings() settings.setValue("window-size", self.size()) settings.setValue("window-position", self.pos()) settings.setValue("window-title", self.windowTitle()) settings.sync() event.accept() def main(): # Set organization and app name (used by QSettings) QCoreApplication.setOrganizationName(ORGANIZATION_NAME) QCoreApplication.setApplicationName(APPLICATION_NAME) app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec()) if __name__ == '__main__': main() ``` -------------------------------- ### Show Yes/No Message Box Source: https://context7.com/erriez/pyside6-getting-started/llms.txt Use QMessageBox.question() to display a dialog for user confirmation with customizable buttons and a default selection. This is useful for actions that require explicit user consent before proceeding. ```python from PySide6.QtWidgets import QApplication, QWidget, QLabel, QMessageBox import sys class Window(QWidget): def __init__(self): super().__init__() self.resize(200, 150) self.setWindowTitle('Message box') label = QLabel('Close this window to\nshow message box', self) label.move(5, 5) def closeEvent(self, event): # Show confirmation dialog before closing answer = QMessageBox.question( self, 'Message', "Are you sure to quit?", QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, QMessageBox.StandardButton.No # Default button ) if answer == QMessageBox.StandardButton.Yes: event.accept() # Allow close else: event.ignore() # Cancel close def main(): app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec()) if __name__ == '__main__': main() ``` -------------------------------- ### Progress Bar with Timer Source: https://context7.com/erriez/pyside6-getting-started/llms.txt Shows how to use QProgressBar to display operation progress, updated periodically using QBasicTimer. Override timerEvent() to handle timer ticks and update the progress bar's value. ```python from PySide6.QtWidgets import QApplication, QWidget, QPushButton, QProgressBar, QGridLayout from PySide6.QtCore import QBasicTimer import sys class Window(QWidget): def __init__(self): super().__init__() self.resize(250, 150) self.setWindowTitle('QProgressBar') # Create progress bar self.progress_bar = QProgressBar() self.progress_bar.setGeometry(30, 40, 200, 25) # Create start/stop button self.button_start = QPushButton('Start') self.button_start.clicked.connect(self.on_button_start) # Timer for progress updates self.timer = QBasicTimer() self.step = 0 # Layout grid = QGridLayout() grid.addWidget(self.progress_bar, 0, 0) grid.addWidget(self.button_start, 0, 1) self.setLayout(grid) def timerEvent(self, e): if self.step >= 100: self.timer.stop() self.step = 0 self.button_start.setText('Finished') else: self.step += 1 self.progress_bar.setValue(self.step) def on_button_start(self): if self.timer.isActive(): self.timer.stop() self.button_start.setText('Start') else: self.timer.start(50, self) # 50ms interval self.button_start.setText('Stop') def main(): app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec()) if __name__ == '__main__': main() ``` -------------------------------- ### Table Widget for Spreadsheet Data Source: https://context7.com/erriez/pyside6-getting-started/llms.txt Demonstrates how to create and populate a QTableWidget to display spreadsheet-like data. Use setHorizontalHeaderLabels() for column headers and setItem() to add data to cells. ```python from PySide6.QtWidgets import QApplication, QWidget, QTableWidget, QTableWidgetItem, QVBoxLayout import sys class Window(QWidget): def __init__(self): super().__init__() self.resize(400, 250) self.setWindowTitle("SpreadSheet example") # Create table with 6 rows and 3 columns self.table = QTableWidget(6, 3) # Set column headers self.table.setHorizontalHeaderLabels(["Name", "Age", "Gender"]) # Fill table with data data = [ ("Jan", "53", "Male"), ("Henk", "45", "Male"), ("Linda", "18", "Female"), ("Kees", "72", "Male"), ("Lotte", "39", "Female"), ("Anne", "28", "Female"), ] for row, (name, age, gender) in enumerate(data): self.table.setItem(row, 0, QTableWidgetItem(name)) self.table.setItem(row, 1, QTableWidgetItem(age)) self.table.setItem(row, 2, QTableWidgetItem(gender)) # Add table to layout self.vBox = QVBoxLayout() self.vBox.addWidget(self.table) self.setLayout(self.vBox) def main(): app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec()) if __name__ == '__main__': main() ``` -------------------------------- ### Create Python Virtual Environment Source: https://github.com/erriez/pyside6-getting-started/blob/main/SETUP_VSCode.md Use this command to create a new Python virtual environment for your project. VSCode will automatically activate it. ```bash python -m venv .venv ``` -------------------------------- ### Open File Dialog Source: https://context7.com/erriez/pyside6-getting-started/llms.txt Use QFileDialog.getOpenFileName() to allow users to select a file. It returns the selected file path and a filter string. Always validate the returned path to ensure the file exists and is accessible before attempting to open it. ```python from PySide6.QtWidgets import QApplication, QMainWindow, QTextEdit, QFileDialog from PySide6.QtGui import QAction, QIcon import os import sys class Window(QMainWindow): def __init__(self): super().__init__() self.resize(400, 300) self.setWindowTitle('File dialog') self.textEdit = QTextEdit() self.setCentralWidget(self.textEdit) file_open = QAction(QIcon('../images/open.png'), 'Open', self) file_open.setShortcut('Ctrl+O') file_open.setStatusTip('Open new File') file_open.triggered.connect(self.show_dialog) menubar = self.menuBar() menu_file = menubar.addMenu('&File') menu_file.addAction(file_open) self.statusBar().showMessage('Click File | Open to read a file') def show_dialog(self): # Open file dialog starting at /home path, _ = QFileDialog.getOpenFileName(self, 'Open file', '/home') if not path: self.statusBar().showMessage('No file selected') elif not os.path.exists(path): self.statusBar().showMessage('File {} not found'.format(path)) else: try: with open(path, 'r') as f: data = f.read() self.textEdit.setText(data) self.statusBar().showMessage('File {} opened'.format(path)) except OSError as err: self.statusBar().showMessage(str(err)) def main(): app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec()) if __name__ == '__main__': main() ``` -------------------------------- ### Checkbox with Tristate Support Source: https://context7.com/erriez/pyside6-getting-started/llms.txt Demonstrates how to create a QCheckBox that supports tristate functionality (checked, unchecked, partially checked). Connect to the stateChanged signal to handle state transitions. ```python from PySide6.QtWidgets import QApplication, QWidget, QCheckBox from PySide6.QtCore import Qt import sys class Window(QWidget): def __init__(self): super().__init__() self.resize(250, 150) self.setWindowTitle('QCheckBox') # Create tristate checkbox checkbox = QCheckBox('Show title', self) checkbox.move(20, 20) checkbox.toggle() # Start checked checkbox.setTristate(True) # Enable third state checkbox.stateChanged.connect(self.on_checkbox_change) def on_checkbox_change(self, state): # Convert int state to Qt.CheckState enum state = Qt.CheckState(state) if state == Qt.CheckState.Unchecked: self.setWindowTitle('Unchecked') elif state == Qt.PartiallyChecked: self.setWindowTitle('PartiallyChecked') elif state == Qt.Checked: self.setWindowTitle('Checked') def main(): app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec()) if __name__ == '__main__': main() ``` -------------------------------- ### Emit Custom Signal to Close Window Source: https://context7.com/erriez/pyside6-getting-started/llms.txt Shows how to define and emit custom signals for inter-object communication. A custom signal 'closeApp' is defined and connected to the window's close method, triggered by a mouse press event. Requires importing Signal and QObject from QtCore. ```python from PySide6.QtWidgets import QApplication, QMainWindow, QLabel from PySide6.QtCore import Signal, QObject import sys # Define custom signal class class Communicate(QObject): closeApp = Signal() class Window(QMainWindow): def __init__(self): super().__init__() self.resize(250, 150) self.setWindowTitle('Emit signal') label = QLabel('Click to close window', self) label.setGeometry(5, 50, 160, 40) # Create signal object and connect to window close self.c = Communicate() self.c.closeApp.connect(self.close) def mousePressEvent(self, event): # Emit custom signal when mouse is pressed self.c.closeApp.emit() def main(): app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec()) if __name__ == '__main__': main() ``` -------------------------------- ### Show Text Input Dialog Source: https://context7.com/erriez/pyside6-getting-started/llms.txt Use QInputDialog.getText() to prompt the user for text input. It returns the entered text and a boolean indicating if the OK button was pressed. This is suitable for simple data entry tasks. ```python from PySide6.QtWidgets import QApplication, QWidget, QPushButton, QLineEdit, QInputDialog import sys class Window(QWidget): def __init__(self): super().__init__() self.resize(300, 100) self.setWindowTitle('Input dialog') self.button = QPushButton('Dialog', self) self.button.move(20, 20) self.button.clicked.connect(self.show_dialog) self.line_edit = QLineEdit(self) self.line_edit.move(130, 22) def show_dialog(self): # Show text input dialog text, ok = QInputDialog.getText(self, 'Input Dialog', 'Enter your name:') if ok: self.line_edit.setText(str(text)) def main(): app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec()) if __name__ == '__main__': main() ``` -------------------------------- ### Implement Simple Drag and Drop in PySide6 Source: https://context7.com/erriez/pyside6-getting-started/llms.txt Enable drag-and-drop functionality by setting acceptDrops to True on the target widget and dragEnabled to True on the source widget. Override dragEnterEvent to accept drops and dropEvent to handle the dropped data. ```python from PySide6.QtWidgets import QApplication, QWidget, QPushButton, QLineEdit import sys class Button(QPushButton): def __init__(self, title, parent): super(Button, self).__init__(title, parent) self.setAcceptDrops(True) # Enable drop target def dragEnterEvent(self, e): # Accept text/plain mime type if e.mimeData().hasFormat('text/plain'): e.accept() else: e.ignore() def dropEvent(self, e): # Set button text to dropped content self.setText(e.mimeData().text()) class Window(QWidget): def __init__(self): super().__init__() self.resize(350, 150) self.setWindowTitle('Simple Drag & Drop') # Line edit with drag enabled qe = QLineEdit('', self) qe.setDragEnabled(True) qe.setText('Drag to the button') qe.selectAll() qe.setFixedWidth(150) qe.move(30, 65) # Button that accepts drops button = Button("Button", self) button.move(230, 65) def main(): app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec()) if __name__ == '__main__': main() ``` -------------------------------- ### Print Color Names with PySide6 Source: https://github.com/erriez/pyside6-getting-started/blob/main/15_misc/README.md This script prints a list of available color names supported by PySide6. It's useful for identifying color constants. ```bash > python .\15_misc\02_print_color_names.py aliceblue antiquewhite aqua aquamarine azure beige ... ``` -------------------------------- ### Execute Delayed Actions with QTimer.singleShot Source: https://context7.com/erriez/pyside6-getting-started/llms.txt QTimer.singleShot() is used to execute a callback function after a specified delay. This is useful for one-time scheduled tasks or timeouts. ```python from PySide6.QtWidgets import QApplication from PySide6.QtCore import QTimer import sys def main(): print('Waiting to quit application...') # Create QApplication object app = QApplication([]) # Close application after 3 seconds (3000 milliseconds) QTimer.singleShot(3000, app.quit) # Application loop runs until quit sys.exit(app.exec()) if __name__ == "__main__": main() ``` -------------------------------- ### Connect Slider Signal to LCD Slot Source: https://context7.com/erriez/pyside6-getting-started/llms.txt Illustrates Qt's signals and slots mechanism by connecting a QSlider's valueChanged signal to a QLCDNumber's display slot. This allows the LCD to update automatically when the slider's value changes. Ensure QLCDNumber and QSlider are imported. ```python from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout, QLCDNumber, QSlider from PySide6.QtCore import Qt import sys class Window(QWidget): def __init__(self): super().__init__() self.resize(250, 150) self.setWindowTitle('Signal & slot') # Create LCD number display widget lcd = QLCDNumber(self) # Create horizontal slider with range 0-100 slider = QSlider(Qt.Horizontal, self) slider.setMinimum(0) slider.setMaximum(100) # Add widgets to vertical box layout vbox = QVBoxLayout() vbox.addWidget(lcd) vbox.addWidget(slider) self.setLayout(vbox) # Connect slider's valueChanged signal to LCD's display slot slider.valueChanged.connect(lcd.display) def main(): app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec()) if __name__ == '__main__': main() ``` -------------------------------- ### VSCode Debug Configuration for Python Source: https://github.com/erriez/pyside6-getting-started/blob/main/SETUP_VSCode.md This JSON configuration is generated by VSCode for debugging Python files. It specifies the debugger type, launch request, program to run, and console type. ```json { "version": "0.2.0", "configurations": [ { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal" } ] } ``` -------------------------------- ### Handle Key Press Events in PySide6 Source: https://context7.com/erriez/pyside6-getting-started/llms.txt Override keyPressEvent to detect keyboard input. Use event.key() for specific keys and event.text() for character input. Closes the window when the Escape key is pressed. ```python from PySide6.QtWidgets import QApplication, QWidget, QLabel from PySide6.QtCore import Qt import sys class Window(QWidget): def __init__(self): super().__init__() self.resize(250, 150) self.setWindowTitle('Event handler') self.label = QLabel('Press a key...', self) self.label.move(20, 20) def keyPressEvent(self, event): # Display pressed key self.label.setText('Key press: {}'.format(event.text())) # Close window on Escape key if event.key() == Qt.Key_Escape: self.close() def main(): app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec()) if __name__ == '__main__': main() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.