from PySide2.QtWidgets import QApplication, QMainWindow app = QApplication([]) window = QMainWindow() window.show() app.exec_()
from PySide2.QtWidgets import QApplication, QMainWindow, QPushButton app = QApplication([]) window = QMainWindow() button = QPushButton('Click me!', window) def on_button_clicked(): print('Button clicked!') button.clicked.connect(on_button_clicked) window.show() app.exec_()
from PySide2.QtWidgets import QApplication, QMainWindow, QPushButton app = QApplication([]) window = QMainWindow() button = QPushButton('Click me!', window) # Set the button's background color to red button.setStyleSheet('background-color: red;') window.show() app.exec_()In this example, we set the style sheet of the `QPushButton` to change its background color to red. The `setStyleSheet()` method can be used to apply CSS-like styles to Qt widgets. Overall, `PySide2.QtWidgets` is a powerful package library for creating desktop applications with Python. It provides a wide range of GUI elements and event handling features that can be used to create complex and responsive user interfaces.