【PySide2学习笔记】2_一个简单的按键应用(涉及信号和槽)

#!/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_()

运行结果如下:


按键反馈.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 【前言】 从日本回来将近2个月,游记却迟迟无法提笔。 可能,对于这个国家,我没有办法客观地去评价。也不想只是写个干...
    48aa5fdd9849阅读 2,311评论 0 2
  • 我很乐意用谢天笑的歌词作为题目。说实话,现在的九零后零零后里,知道谢天笑、崔健、窦唯的人不超十分之一。我很庆...
    翊觋阅读 896评论 0 0
  • 参与前言 加入007写作之后,了解学习财商管理入门的书就是《富爸爸穷爸爸》,当时就买了此书,但买得是实践版,有些看...
    员子圆梦阅读 930评论 10 2

友情链接更多精彩内容