#!/usr/bin/python
import sys
from PySide2.QtWidgets import QApplication, QPushButton
from PySide2.QtCore import Slot
# Signals and slots is a Qt feature that lets your graphical widgets
# communicate with other graphical widgets or your python code.
# logs the message to the console
@Slot()
# The @Slot() is a decorator that identifies a function as a slot.
def say_hello():
print("Button clicked, Hello!")
# Create the Qt Application
app = QApplication(sys.argv)
# create the clickable button, which is a QPushButton instance
button = QPushButton("Click me")
# The QPushButton has a predefined signal called clicked,
# which is triggered every time the button is clicked.
# connect this signal to the say_hello() function
button.clicked.connect(say_hello)
button.show()
# Run the main Qt loop
app.exec_()
运行结果如下: