Python Pyside:QLineEdit接受多个输入
我在Qt设计器中开发了一个GUI,用户可以在Python Pyside:QLineEdit接受多个输入,python,python-3.x,pyside,qlineedit,Python,Python 3.x,Pyside,Qlineedit,我在Qt设计器中开发了一个GUI,用户可以在QLineEdit中输入两个值,当用户点击enter时,它会执行一些数学计算 问题是一旦输入了值并在输出后按下enter键,我就无法将输入输入到QLineEdit,但每次都必须重新启动GUI。这是我的密码: def entervalues(self): if self.RotationEdit.text() != "" and self.TiltEdit.text() != "": self.Rotati
QLineEdit
中输入两个值,当用户点击enter时,它会执行一些数学计算
问题是一旦输入了值并在输出后按下enter键,我就无法将输入输入到QLineEdit
,但每次都必须重新启动GUI。这是我的密码:
def entervalues(self):
if self.RotationEdit.text() != "" and self.TiltEdit.text() != "":
self.RotationEdit = str(self.RotationEdit.text())
self.TiltEdit = str(self.TiltEdit.text())
self.pass_arguments.emit("self.RotationEdit","self.TiltEdit")
else:
QMessageBox.information(self, "Error","No Values Entered")
如果我尝试输入值并按enter键,则会显示属性错误
line 100, in entervalues
if self.RotationEdit.text() != "" and self.TiltEdit.text() != "":
AttributeError: 'str' object has no attribute 'text'
问题出现在代码中,您正在更改对象
self.RotationEdit
self.RotationEdit = str(self.RotationEdit.text())
当您最初声明这是一个QLineEdit时,但随后您分配了一个字符串。当您重新使用它时,它仍然是字符串,因此未定义text()
函数。我建议创建一个包含这些值的新变量您将在另一个函数中使用的
def entervalues(self):
if self.RotationEdit.text() != "" and self.TiltEdit.text() != "":
self.pass_arguments.emit(self.RotationEdit.text(),self.TiltEdit.text())
else:
QMessageBox.information(self, "Error","No Values Entered")
这些值self.RotationEdit和self.TiltEdit被传递到另一个函数中,该函数在按下enter键编辑QLineEdit
self.pass\u arguments.emit(self.RotationEdit.text(),self.TiltEdit.text())时执行数学计算。
。