import sys
from PyQt5.QtWidgets import QDialog, QApplication, QMainWindow, QWidget
from PyQt5 import uic
import linecache
class Dialog(QDialog):
def __init__(self):
super().__init__()
uic.loadUi("caldia.ui", self)
self.cal.clicked.connect(self.cement_cal)
self.save_button.clicked.connect(self.save_in)
#============write data=============
def save_in(self):
s_text = self.sand_in.text()
m_text = self.Metal_in.text()
ce_text = self.Cement_in.text()
data_file=open('data.txt',"w")
data_file.write(str(s_text)+"
")
data_file.write(str(m_text)+"
")
data_file.write(str(ce_text))
data_file.close()
print(self.metal_r)
#==========get text file data =======
global sand_r,metal_r,cement_r
sand_r=linecache.getline("data.txt",1)
metal_r=linecache.getline("data.txt",2)
cement_r=linecache.getline("data.txt",3)
#========calculation=======
def cement_cal(self):
load_txt_cem=self.cement_r()
load_txt_met=self.metal_r()
load_txt_san=self.sand_r()
print(str(load_txt_cem))
enterd_value=self.input.text()
input_int=int(enterd_value)
cem=round((input_int*cement_r/1000),2)
san=round((input_int*sand_r/1000),2)
met=round((input_int*metal_r/1000),2)
san_cu=round(san/2.8,2)
met_cu=round(met/2.8,2)
if __name__ == '__main__':
caldia = QApplication(sys.argv)
demo = Dialog()
demo.show()
try:
sys.exit(caldia.exec_())
except SystemExit:
print("closing window")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…