Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.4 kB
2
Indexable
from PyQt6.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QLabel, QLineEdit

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

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

        # Create a label for the title
        self.title_label = QLabel('My PyQt6 App')

        # Create a text box
        self.text_box = QLineEdit()
        self.text_box.setPlaceholderText('Enter text here')

        # Create a layout and add the button, title label, and text box to it
        layout = QVBoxLayout(self)
        layout.addWidget(self.title_label)
        layout.addWidget(self.button)
        layout.addWidget(self.text_box)

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

        # Set the window properties
        self.setWindowTitle('PyQt6 Example with Button and TextBox')
        self.setGeometry(100, 100, 400, 200)

    def on_button_click(self):
        # Update the text box content when the button is clicked
        self.text_box.setText('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