在此代码段中,我试图将参数传递给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_())