【发布时间】:2020-07-18 07:14:06
【问题描述】:
我正在尝试将计算的浮点结果放入 PyQT5 中的 LineEdit 中。我知道 LineEdit 引用是正确的,因为我可以将文本更改为设定值,例如“测试”,但我无法通过 setText 显示我的计算变量。 所有方程等都正常工作并打印到 shell,这只是我正在努力处理的 GUI 的输出。 我需要进行浮点转换,因为如果我不这样做,逻辑将无法工作。我是否需要将其转换回其他内容以使其与 setText 一起使用? 我已经在代码中为每个阶段放置了#Default 数据示例和答案。
from PyQt5 import QtWidgets, uic
import sys
import pandas as pd
from pandas import DataFrame
import numpy as np
class Ui(QtWidgets.QMainWindow):
def __init__(self):
super(Ui,self).__init__()
uic.loadUi('BinGrid.ui',self)
self.button=self.findChild(QtWidgets.QPushButton,'P6BGCbtn')
self.button.clicked.connect(self.P6_to_BGC)
self.show() ## Show the Gui
def P6_to_BGC(self,MainWindow): #### Find Bin Grid centre from Bin Grid Origin ####
BinX=self.BinXin.text() ## Default set to 6.25 in Qt Designer
BinY=self.BinYin.text() ## Default set to 6.25
L_Theta=self.L_Thetain.text() ## Default set to 329.075
BGO_E=self.BGO_Ein.text() ## Default set to 123456.123
BGO_N=self.BGO_Nin.text() ## Default set to 1234567.123
BinX=float(BinX)
BinY=float(BinY)
L_Theta=float(L_Theta)
Line_Theta=np.radians(L_Theta)
BGO_E=float(BGO_E)
BGO_N=float(BGO_N)
Bin_Theta=np.arctan((0.5*BinX)/(0.5*BinY))
Bin_Hyp=((0.5*BinX)**2+(0.5*BinY)**2)**0.5
BGC_E=round(BGO_E+Bin_Hyp*np.sin(Bin_Theta+Line_Theta),3) ## Output is 123457.075
BGC_N=round(BGO_N+Bin_Hyp*np.cos(Bin_Theta+Line_Theta),3) ## Output is 1234571.287
self.BGC_Ein.setText('BGC_E') ## This works to set the box to 'BGC_E'
self.BGC_Ein.repaint() ## Corrects for know 'non-display until focus' bug
self.BGC_Nin.setText(BGC_N.text()) ## This doesn't work to set the text to the value of my variable
self.BGC_Nin.repaint()
app=QtWidgets.QApplication(sys.argv)
window=Ui()
app.exec_()
【问题讨论】:
标签: python pyqt pyqt5 python-3.8 qlineedit