Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我已经从pyqt designer设计了ui,现在我想将按钮和标签连接在一起_Python_User Interface_Pyqt_Pyqt5_Qt Designer - Fatal编程技术网

Python 我已经从pyqt designer设计了ui,现在我想将按钮和标签连接在一起

Python 我已经从pyqt designer设计了ui,现在我想将按钮和标签连接在一起,python,user-interface,pyqt,pyqt5,qt-designer,Python,User Interface,Pyqt,Pyqt5,Qt Designer,如何定义findqlabel、Qpushbutton和QlineEdit来修复该属性错误 from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * import sys from PyQt5.uic import loadUiType Ui, _ = loadUiType('tempconverter.ui') class MainApp(QMainWindow , Ui):

如何定义findqlabel、Qpushbutton和QlineEdit来修复该属性错误

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys

from PyQt5.uic import loadUiType

Ui, _ = loadUiType('tempconverter.ui')

class MainApp(QMainWindow , Ui):
    def __init__(self):
        QMainWindow.__init__(self)
        self.setupUi(self)
        self.pushButton.clicked.connect(self.cal)

    def cal(self):
        temp = self.temp_in.text
        far=int(temp)*9/5+32
        self.answer.setText(str(far))

def main():
    app = QApplication(sys.argv)
    window = MainApp()
    window.show()
    app.exec_()

if __name__ == "__main__":
    main()
回溯(最近一次呼叫最后一次): 文件“d:/pythonproj/temp_test2.py”,第17行,cal格式 temp=文本中的self.temp\u AttributeError:“MainApp”对象没有属性“temp\u in”``


您确实应该考虑从定义了TwittIn的.UI文件中发布部分,但我可以看到一些错误。p> 首先,你有这一行:

temp = self.temp_in.text
这应该是:

temp = self.temp_in.text()
要使用QLineEdits检索文本,需要运行函数text()(它不是参数)


从错误消息中,您似乎使用了错误的QLineEdit名称。是否可能您无意中使用了QLabel的名称?可能有帮助的是运行将.ui文件转换为Python代码。这将允许您使用代码完成来查看IDE中定义了哪些元素。

您好,欢迎使用StackOverflow!每当你回答一个问题,考虑包括一个。在您的例子中,您没有提供“tempconverter.ui”代码,这似乎是理解程序运行情况所必需的。请编辑您的答案并将其包括在内,以便我们可以尝试并帮助您。