window.show() sys.exit(app.exec()) 4.1 Signals and Slots Signals are emitted when an event occurs (e.g., button click). Slots are functions that respond to signals.
# Signals self.add_button.clicked.connect(self.add_task) self.delete_button.clicked.connect(self.delete_task)
def mousePressEvent(self, event): print(f"Mouse click at (event.x(), event.y())") This example combines signals, slots, layouts, and widgets. pyqt6 tutorial
button = QPushButton("Click Me", window) button.setGeometry(50, 50, 100, 30) # x, y, width, height
class MyWindow(QWidget): def __init__(self): super().__init__() self.setWindowTitle("Events") def keyPressEvent(self, event): print(f"Key pressed: event.text()") window
# Widgets self.input_field = QLineEdit() self.input_field.setPlaceholderText("Enter a task...") self.add_button = QPushButton("Add Task") self.delete_button = QPushButton("Delete Selected") self.task_list = QListWidget()
Abstract PyQt6 is a set of Python bindings for the Qt6 application framework, enabling developers to create cross-platform desktop applications with native look and feel. This paper provides a structured tutorial on PyQt6, covering installation, fundamental concepts (signals, slots, widgets, layouts), event handling, and practical application development. By the end, readers will be able to build functional GUI applications. 1. Introduction Qt is a powerful C++ framework for GUI development. PyQt6, developed by Riverbank Computing, allows Python programmers to harness Qt’s capabilities. Compared to Tkinter, PyQt6 offers more widgets, better styling (QSS), and advanced features like OpenGL integration, multimedia, and networking. button = QPushButton("Click Me", window) button
pip install PyQt6 Verify installation: