Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.0k views
in Technique[技术] by (71.8m points)

python - How to assign and use this sand_r, metal_r, cement_r values in cement_cal method?

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")

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...