from qtpy.QtWidgets import QApplication, QMainWindow # Create a QApplication object app = QApplication([]) # Create a QMainWindow object window = QMainWindow() # Set the window properties window.setWindowTitle('My Application') window.setGeometry(100, 100, 800, 600) # Show the window window.show() # Start the event loop app.exec_()
from qtpy.QtWidgets import QApplication, QMainWindow, QPushButton # Create a QApplication object app = QApplication([]) # Create a QMainWindow object window = QMainWindow() # Create a QPushButton object button = QPushButton('Click me!', window) # Define a function to run when the button is clicked def on_button_click(): print('Button was clicked!') # Connect the button to the function button.clicked.connect(on_button_click) # Show the window window.show() # Start the event loop app.exec_()In this example, we also import the QPushButton class from the QtWidgets module. We create a QPushButton object and add it to the main window. We then define a function that will be called when the button is clicked, and use the `clicked.connect()` method to connect the function to the button's `clicked` signal. When the button is clicked, the `on_button_click()` function will be executed. In both examples, we are using the qtpy package library to access the QtWidgets module.