PyQt5-插槽不接受信号回调的参数

时间:2019-04-18 20:24:07

标签: python pyqt5

在此代码段中,我试图将参数传递给buttonClicked(),并且参数类型为NoneType失败。为什么我的函数不接受“ 1”字符串参数?

import sys
from PyQt5.QtWidgets import QMainWindow, QPushButton, QApplication 

class Example(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        btn1 = QPushButton("Button 1", self)
        btn1.move(30, 50)

        # This code ties the slots and signals together
        # clicked is the SIGNAL
        btn1.clicked.connect(self.buttonClicked("1"))

        self.statusBar()
        self.setGeometry(300, 300, 300, 230)
        self.setWindowTitle('Event sender')
        self.show()


    def buttonClicked(self, buttonNumber):
        sender = self.sender()
        self.statusBar().showMessage(buttonNumber + ' was pressed')

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

0 个答案:

没有答案