AttributeError: 'PyQt5.QtCore.pyqtSignal' object has no attribute 'connect'
pyqt5信号要定义为类属性
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from PyQt5.Qt import *
import sys
class Win(QWidget):
my_singal = pyqtSignal(str)
def __init__(self):
super().__init__()
self.initUI()
self.setWindowTitle('Main Window')
self.setGeometry(300, 300, 300, 150)
def initUI(self):
btn = QPushButton("Button",self)
btn.move(50,50)
self.my_singal.connect(self.mysignal)
btn.clicked.connect(self.prn)
def prn(self):
print("Print Test")
self.my_singal.emit("My Slot")
def mysignal(self,para):
print(para)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Win()
ex.show()
app.exec_()