问题遇到的现象和发生背景
主代码
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QDialog
from jsscjck import Ui_Dialog
import math
def comput_degree(a_f, f_f):
degree = 2 * math.atan(a_f / f_f / 2)
return degree
class Using_test(QDialog, Ui_Dialog):
def __init__(self, *args, **kwargs):
super(Using_test, self).__init__(*args, **kwargs)
self.setupUi(self)
self.pushButton.clicked.connect(self.calcu())
def calcu(self):
a = self.lineEdit.text().todouble()
b = self.lineEdit_2.text().todouble()
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/627209855246151.png "#left")
f = self.lineEdit_3.text().todouble()
alpha = math.degrees(comput_degree(a, f))
beta = math.degrees(comput_degree(b, f))
print("alpha = %.4f" % alpha)
print("beta = %.4f" % beta)
self.lineEdit_4.setText(alpha)
self.lineEdit_5.setText(beta)
if __name__ == '__main__':
app = QApplication(sys.argv)
win = Using_test()
win.show()
sys.exit(app.exec_())
窗体代码
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'D:\python\python_work\计算视场角.ui'
#
# Created by: PyQt5 UI code generator 5.9.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(610, 345)
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(120, 100, 31, 31))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(Dialog)
self.label_2.setGeometry(QtCore.QRect(120, 140, 31, 31))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(Dialog)
self.label_3.setGeometry(QtCore.QRect(116, 180, 31, 31))
self.label_3.setObjectName("label_3")
self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(150, 100, 113, 31))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_2.setGeometry(QtCore.QRect(150, 140, 113, 31))
self.lineEdit_2.setObjectName("lineEdit_2")
self.lineEdit_3 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_3.setGeometry(QtCore.QRect(150, 180, 113, 31))
self.lineEdit_3.setObjectName("lineEdit_3")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(240, 240, 92, 28))
self.pushButton.setObjectName("pushButton")
self.label_4 = QtWidgets.QLabel(Dialog)
self.label_4.setGeometry(QtCore.QRect(330, 110, 72, 31))
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(Dialog)
self.label_5.setGeometry(QtCore.QRect(330, 150, 72, 31))
self.label_5.setObjectName("label_5")
self.lineEdit_4 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_4.setGeometry(QtCore.QRect(400, 110, 113, 31))
self.lineEdit_4.setObjectName("lineEdit_4")
self.lineEdit_5 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_5.setGeometry(QtCore.QRect(400, 150, 113, 31))
self.lineEdit_5.setObjectName("lineEdit_5")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.label.setText(_translate("Dialog", "a:"))
self.label_2.setText(_translate("Dialog", "b:"))
self.label_3.setText(_translate("Dialog", "f:"))
self.pushButton.setText(_translate("Dialog", "计算"))
self.label_4.setText(_translate("Dialog", "水平角α:"))
self.label_5.setText(_translate("Dialog", "垂直角β:"))
窗体见附图
我想在左侧的三个lineedit里面输入数字,然后通过函数计算输出在右面的两个里面。