PyQt5区分确定和取消命令

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

这是使用PyQt5 QDialog的对话框代码。

class QDialogUI(QDialog):
    def __init__(self):

        super().__init__()

        self.okButton = QPushButton("Ok", self)
        self.okButton.clicked.connect(self.acceptCommand)
        self.okButton.clicked.connect(lambda:self.closeCommand(1))

        self.cancelButton = QPushButton("Cancel", self)
        self.okButton.clicked.connect(lambda:self.closeCommand(0))

    def acceptCommand(self):
        ...
        return date, asset, sort, money, text

    def closeCommand(self, status):
        return status

这是主要代码。

def openDialog(self):
    self.dlg = QDialogUI()
    self.dlg.exec_()
    if self.dlg.closeCommand() == 1:
        iD = list(self.dlg.acceptCommand())
        self.params.emit(iD[0],iD[1],iD[2],iD[3],iD[4])

如果我单击okButton或cancelButton,它们都不反应。然后关闭QDialogUI,它显示错误,例如:

TypeError: closeCommand()missing 1 required positional argument: 'status'

[okButton.clicked时如何获得'return of acceptCommand?还是有更好的代码来区分“确定”和“取消”命令?

python python-3.x pyqt pyqt5
1个回答
0
投票
class QDialogUI(QDialog): def __init__(self): super().__init__() self.status = None self.okButton = QPushButton("Ok", self) self.okButton.clicked.connect(self.acceptCommand) self.okButton.clicked.connect(lambda:self.closeCommand(1)) self.cancelButton = QPushButton("Cancel", self) self.okButton.clicked.connect(lambda:self.closeCommand(0)) def acceptCommand(self): ... self.status = date, asset, sort, money, text def closeCommand(self, status): return self.status
© www.soinside.com 2019 - 2024. All rights reserved.