【问题标题】:quantum geographic information system量子地理信息系统
【发布时间】: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 的无效文字:''
  • xy的类型是什么?你可以通过print type(x) 找到这个并打印type(y)。同时打印 x 和 y 中的值。
  • x 和 y 的类型是 unicode,x 和 y 来自将在 lineedit 中输入的用户
  • 如果输入肯定是数字,那么请尝试int(float(x))

标签: python-2.7 pyqt4 qgis


【解决方案1】:

定义运行(自我):

    """Run method that performs all the real work"""
    # show the dialog
    self.dlg.show()
    self.dlg.spinBox.clear()
    self.dlg.spinBox_2.clear()

    # Run the dialog event loop


    result = self.dlg.exec_()
    if result:
        x = self.dlg.spinBox.value()
        y = self.dlg.spinBox_2.value()
        z = x+y
    # 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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-19
    • 2013-05-09
    相关资源
    最近更新 更多