【发布时间】:2016-10-15 07:56:30
【问题描述】:
def run(self):
"""Run method that performs all the real work"""
# show the dialog
self.dlg.show()
# Run the dialog event loop
x = self.dlg.lineEdit.text()
y = self.dlg.lineEdit_2.text()
z = int(x)+int(y)
result = self.dlg.exec_()
# See if OK was pressed
# Do something useful here - delete the line containing pass and
# substitute with your code.
QMessageBox.information(self.iface.mainWindow(),"sum is =", "%d" %z)
但它在z=int(x)+int(y).x 中显示 ValueError 并且 y 来自行编辑框..x 的类型和 y 是 unicode...
我应该如何添加 x 和 y?
【问题讨论】:
-
请发布错误信息。
-
ValueError: int() 基数为 10 的无效文字:''
-
x和y的类型是什么?你可以通过print type(x)找到这个并打印type(y)。同时打印 x 和 y 中的值。 -
x 和 y 的类型是 unicode,x 和 y 来自将在 lineedit 中输入的用户
-
如果输入肯定是数字,那么请尝试
int(float(x))。
标签: python-2.7 pyqt4 qgis