PyQt5基础学习-pyqSignal(object)(自定义信号) 1.pyqtSignal().emit(发送信号) 2.pyqtSignal().connect(连接槽函数)
定义信号发射器,将其与槽函数进行绑定, 通过发送信号来触发槽函数,实现自定义信号
CustomSignal.py
""" 自定义信号 pyqtSignal() """ from PyQt5.QtCore import * class MyTypeSignal(QObject): #定义一个信号 sendmsg = pyqtSignal(object) #触发信号 def run(self): self.sendmsg.emit("Hello PyQt5") #构造槽函数 class MySlot(QObject): def get(self, msg): print("信息:" + msg) if __name__ == "__main__": send = MyTypeSignal() slot = MySlot() send.sendmsg.connect(slot.get) send.run() #断开连接 send.sendmsg.disconnect(slot.get) send.run()
每天更新pyQt5内容