如何在使用python 3.4的方法中将`ObjectName`的名称像`self.lineEdit_260`作为参数传递? [重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

如何将ObjectName的名称像self.lineEdit_260一样传递给使用python 3.4的方法中的参数?

self.Open_Fan_J104_A_stage_2(no=self.lineEdit_260.text()))

def Open_Fan_J104_A_stage_2(self,no):

    if no=='' and self.lineEdit_247.text()=='':
        print(type(self.lineEdit_260.text()))
        self.start_time=datetime.datetime.now()
        self.lineEdit_260.setText(str(self.start_time))
    elif self.lineEdit_247.text()=='':

        QMessageBox.information(self, 'x')

    else:
        self.lineEdit_260.setText('')
        self.start_time = datetime.datetime.now()
        self.lineEdit_260.setText(str(self.start_time))

    self.lineEdit_247.setText('')
    self.lineEdit_241.setText('')

当我运行此代码时:

self.pushButton_123.clicked.connect( self.Open_Fan_J104_A_stage_2(no=self.lineEdit_260.text()))

TypeError:参数1具有意外类型'NoneType'

python python-3.x function parameter-passing pyqt5
1个回答
0
投票

我认为,Open_Fan_J104_A_stage_2期待一个callable,因为缺乏信息。所以试试吧,

self.Open_Fan_J104_A_stage_2(lambda: self.lineEdit_260.text()))
© www.soinside.com 2019 - 2024. All rights reserved.