【发布时间】:2017-11-20 01:20:08
【问题描述】:
在我的 maingui (PyQt5) 脚本中使用 *args 时出现两次错误,不知道为什么。我在做什么不是 pythonic/pyqt5 风格的?
第一次尝试:
从 GUI 中调用时出现错误的代码行:
def createActions(self):
...
self.lineEdit.returnPressed.connect(self.updateUi('buttons'))
错误:
Traceback...(snippet)
...
self.lineEdit.returnPressed.connect(self.updateUi('buttons'))
TypeError: argument 1 has unexpected type 'NoneType'
它可能不是一个函数...所以我将其更改为我的第二次尝试,正如 Mark Summerfield 在 RapidGUI Programming with python and PyQt 中所述,第 133 页:
def createActions(self):
...
self.lineEdit.returnPressed.connect(functools.partial(self.updateUi, 'buttons'))
def updateUi(self, *args):
if args == 'color_update':
color = self.colorCh2comboBox.currentText()
if color == 'Violet':
print '%s is purple' % color
else:
print color
elif args== 'buttons':
try:
print 'yes'
...
except:
print "no"
...
else:
print "Unknown action : %s" % args
结果:“未知操作:按钮
在我尝试的第三次尝试中:
def updateUi(self, *args):
argument = str(args) # just to be sure I'll parse a string and not something else.
...etc... # as above.
还能是什么?
【问题讨论】:
标签: python-2.7 pyqt5