Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.0 kB
6
Indexable
from PyQt6.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout

class MyWindow(QWidget):
    def __init__(self):
        super().__init__()

        # Create a button
        self.button = QPushButton('Click me!')

        # Connect the button click event to a function
        self.button.clicked.connect(self.on_button_click)

        # Create a layout and add the button to it
        layout = QVBoxLayout(self)
        layout.addWidget(self.button)

        # Set the layout for the main window
        self.setLayout(layout)

        # Set the window properties
        self.setWindowTitle('Simple PyQt6 Example')
        self.setGeometry(100, 100, 300, 200)

    def on_button_click(self):
        print('Button clicked!')

if __name__ == '__main__':
    app = QApplication([])  # Create the application instance
    window = MyWindow()       # Create an instance of your window class
    window.show()             # Display the window
    app.exec()                # Run the application event loop
Leave a Comment