# -*- coding: utf-8 -*-
from PyQt5.QtCore import QObject, pyqtSignal
# 信号对象
class QTypeSignal(QObject):
# 定义一个信号
sendpath = pyqtSignal(str)
def __init__(self):
super(QTypeSignal, self).__init__()
def run(self):
# 发射信号
self.sendpath.emit('img_path')
# 槽对象
class QTypeSlot(QObject):
def __init__(self):
super(QTypeSlot, self).__init__()
# 槽对象里的槽函数
def get(self, msg):
print("QSlot get msg => " + msg)
if __name__ == '__main__':
send = QTypeSignal()
slot = QTypeSlot()
# 1
print('--- 把信号绑定到槽函数 ---')
send.sendpath.connect(slot.get)
send.run()
# 2
print('--- 把信号断开槽函数 ---')
send.sendpath.disconnect(slot.get)
send.run()
PyQt5 信号槽
最新推荐文章于 2022-09-19 11:35:36 发布