【发布时间】:2020-07-17 17:03:50
【问题描述】:
我已经编写了通过 tkinter gui 运行的工作代码(所以我知道数学等工作)并试图将其转换为 PyQt5 Gui(导入 Qt 设计器 .ui 文件而不是在我的“逻辑”中包含代码'.py)。
'print to shell' 只是在那里,所以我可以看到导致失败的阶段。它在数学函数上失败了。如果我删除一个,它会在下一个失败。第一个失败是:
Line_Theta=np.radians(L_Theta)
我是否需要将从 QLineEdit 读取的内容转换为其他内容(如果需要,如何)?我尝试了以下方法但没有成功:
Line_Theta=float(np.radians(L_Theta))
和
L_Theta=float(Line_Theta)
完整代码:
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__() ## Call the inherited classes __init__ method
uic.loadUi('BinGrid.ui',self) ## Load the .ui file
self.button=self.findChild(QtWidgets.QPushButton,'P6BGCbtn') ## Find the button
self.button.clicked.connect(self.P6_to_BGC) ## Remember to pass the defintion/method
self.show() ## Show the Gui
def P6_to_BGC(self,MainWindow): #### Find Bin Grid centre from Bin Grid Origin ####
BinX=self.findChild(QtWidgets.QLineEdit, 'BinXin')
BinY=self.findChild(QtWidgets.QLineEdit, 'BinYin')
L_Theta=self.findChild(QtWidgets.QLineEdit, 'L_Thetain')
BGO_E=self.findChild(QtWidgets.QLineEdit, 'BGO_Ein')
BGO_N=self.findChild(QtWidgets.QLineEdit, 'BGO_Nin')
Line_Theta=np.radians(L_Theta)
print(BinX.text()) ##Print only here to check failure stage
print(BinY.text())
print(L_Theta.text())
print(Line_Theta.text())
print(BGO_E.text())
print(BGO_N.text())
Bin_Theta=np.arctan((0.5*BinX)/(0.5*BinY))
print(Bin_Theta.text())
Bin_Hyp=((0.5*BinX)**2+(0.5*BinY)**2)**0.5
print(Bin_Hyp.text())
BGC_E=round(BGO_E+Bin_Hyp*np.sin(Bin_Theta+Line_Theta),3)
BGC_N=round(BGO_E+Bin_Hyp*np.cos(Bin_Theta+Line_Theta),3)
print(BGC_E.text())
print(BGC_N.text())
self.BGC_Ein.setText(BGC_E.text())
self.BGC_Nin.setText(BGC_E.text())
app=QtWidgets.QApplication(sys.argv) ## Create an instance of QtWidgets.QApplication
window=Ui() ##Create an instance of our class
app.exec_() ##Start the application
BGO_E 和 BGO_N 是东和北(12345.123 和 1234567.123) BinX 和 BinY 均为 6.25(在此示例中) L_Theta 是方向/罗盘方位。例如。 329.075(我需要小数位以确保准确性)。 输出 BGC_E 和 BGC_N 也应该是东向和北向。
【问题讨论】:
标签: python-3.x numpy user-interface pyqt5 qlineedit