# 熟悉信号与槽的使用
# -*- coding: utf-8 -*-
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import sys# 创建信号类
class QTypeSigner(QObject):# 定义一个信号sendmsg = pyqtSignal(object)def __init__(self):super(QTypeSigner, self).__init__()def run(self):# 发射信号self.sendmsg.emit("发射信号")# 创建槽类
class QTypeSlot(QObject):def __init__(self):super(QTypeSlot, self).__init__()def get(self, msg):print("QSlot get msg to" + msg)if __name__ == "__main__":send = QTypeSigner()slot = QTypeSlot()# 绑定信号和槽print("绑定信号和槽")send.sendmsg.connect(slot.get)send.run()# 断开信号和槽print("断开信号和槽")send.sendmsg.disconnect(slot.get)send.run()
关注公众号,获取更多资料