【发布时间】:2020-01-13 02:01:52
【问题描述】:
我可以在部分语句中使用带参数的方法作为参数吗?
我正在使用 partial 并且可以传递字符串,但是当我尝试传递带有变量作为参数的方法时,单击消息框按钮时没有得到任何结果,但是当工具打开并执行 parial 语句时我无需与工具交互即可获得结果
self.ui.psh_bttn_go.clicked.connect(partial(self.yes_no_messagebox, 'poop', 'loop'))# this works
self.ui.psh_bttn_go.clicked.connect(partial(self.yes_no_messagebox, (partial(self.test_fn, 'Help')), (partial(self.test_fn, 'meeeeee!'))))) # This produces nothing
# Using the following methods
def yes_no_messagebox(self, yes_fn, no_fn):
yes_no_msg_box = QMessageBox()
yes_no_msg_box.setWindowTitle("Continue?")
yes_no_msg_box.setText('This is the message box message')
yes_no_msg_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
yes_no_msg_box.setDefaultButton(QMessageBox.No)
yes_no_msg_box_ex = yes_no_msg_box.exec_()
if yes_no_msg_box_ex == QMessageBox.Yes:
yes_fn
elif yes_no_msg_box_ex == QMessageBox.No:
no_fn
def test_fn(self, msg = ''):
print msg
我希望部分语句能够工作,因为我只传递了一个应该被识别为参数的条件。论点是部分陈述是否重要?
【问题讨论】:
标签: python python-2.7 pyqt