from qtpy.QtWidgets import QApplication, QPushButton app = QApplication([]) button = QPushButton('Click me!') button.show() app.exec_()
from qtpy.QtWidgets import QApplication, QWidget, QTextEdit, QVBoxLayout, QPushButton class MyWidget(QWidget): def __init__(self): super().__init__() self.text_edit = QTextEdit() self.button = QPushButton('Print') self.button.clicked.connect(self.print_text) layout = QVBoxLayout() layout.addWidget(self.text_edit) layout.addWidget(self.button) self.setLayout(layout) def print_text(self): text = self.text_edit.toPlainText() print(text) app = QApplication([]) widget = MyWidget() widget.show() app.exec_()This code creates a text box and a button in a window. When the user inputs text into the text box and clicks the button, the input is printed to the console. Package library: PyQt5 (a set of Python bindings for the Qt application framework)