from PyQt5.QtWidgets import QApplication, QWidget app = QApplication([]) window = QWidget() window.show() app.exec_()
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton class MyWindow(QWidget): def __init__(self): super().__init__() button = QPushButton('Click me!', self) button.clicked.connect(self.on_button_clicked) layout = QVBoxLayout() layout.addWidget(button) self.setLayout(layout) def on_button_clicked(self): print('Button clicked!') app = QApplication([]) window = MyWindow() window.show() app.exec_()
from PyQt5.QtWidgets import QApplication, QWidget, QLineEdit class MyWindow(QWidget): def __init__(self): super().__init__() text_input = QLineEdit(self) text_input.returnPressed.connect(self.on_text_input_return_pressed) layout = QVBoxLayout() layout.addWidget(text_input) self.setLayout(layout) def on_text_input_return_pressed(self): text = self.sender().text() print(f'Text entered: {text}') app = QApplication([]) window = MyWindow() window.show() app.exec_()This code creates a window with a text input field that prints the entered text when the return key is pressed. It uses the QLineEdit class provided by PyQt5 QtGui to create the text input field. In conclusion, PyQt5 QtGui library is used for creating graphical user interfaces for desktop applications using Python. The examples shown above are using this library to create simple windows, buttons, and text input fields. The library provides a wide range of GUI elements that can be used to create more complex applications.