Issue
The program has 2 windows that one is the main window and the other is the result window. I want to pass the data where I got the values in getValue() function to the other class which is the result window.
#### THIS PARAMETERS SHOULD PASS TO THE BILLETCALCULATIONRESULTS WINDOW TO CALCULATE ###
def GetValues(self):
self.Diameter = float(self.DiameterQline.text())
self.Height = float(self.HeightQline.text())
self.StartTemp = float(self.StartTempQline.text())
self.FinalTemp = float(self.FinalTempQline.text())
self.HeatingTime = float(self.HeatingTimeQline.text())
I want to do the calculation in the other window and will print the result to the screen. Like
class BilletCalculationResults(QWidget):
def calc():
return str(Main.diameter * 2 )
def billetCalculationPageDesign(self):
### BILLET RESULTS OF CALCULATION PAGE DESIGN ###
self.billetCalSurfaceAreaLabel = QLabel("Surface Area : ")
self.billetCalSurfaceAreaLabel.setStyleSheet('font-size: 12pt; font-family: arial,sans-serif')
str = self.calc()
self.billetCalSurfaceAreaLabelResult = QLabel(str)
You can find the all code below. Thank you
from PyQt5.QtWidgets import *
from PyQt5 import QtCore
import sys
import math
from PyQt5.QtGui import QPixmap,QFont
import sqlite3
class Main(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Calculation")
self.setGeometry(450,100,1250,600)
self.UI()
self.show()
def UI(self):
self.mainDesign()
self.layouts()
def mainDesign(self):
self.setStyleSheet('background-color:white')
#CUSTOMER INFORMATION BUTTONS AND TEXT###
#### CALCULATE BUTTONS###
self.buttonCalcBillet = QPushButton("Calculate")
self.buttonCalcBillet.setStyleSheet(
'background-color: orange;'
'color: black;'
)
### CALCULATE BUTTONS CLICKED ###
self.buttonCalcBillet.clicked.connect(self.billetCalculationResults)
######
self.Title = QLabel("Some Maths")
self.Title.setAlignment(QtCore.Qt.AlignHCenter)
self.Title.setStyleSheet('font-size: 18pt; font-family: arial,sans-serif')
self.DiameterLabel = QLabel("Diameter")
self.DiameterLabel.setStyleSheet('font-size: 12pt; font-family: arial,sans-serif')
self.DiameterQline = QLineEdit()
self.DiameterQline.setPlaceholderText("Please Enter Diameter in mm")
self.DiameterQline.setStyleSheet(
'font-family:Hack,monospace;'
'font:12px;'
'mind-width:20em;'
)
self.HeightLabel = QLabel("Height")
self.HeightLabel.setStyleSheet('font-size: 12pt; font-family: arial,sans-serif')
self.HeightQline = QLineEdit()
self.HeightQline.setPlaceholderText("Please Enter Height in mm")
self.StartTempLabel = QLabel("Start Temperature")
self.StartTempLabel.setStyleSheet('font-size: 12pt; font-family: arial,sans-serif')
self.StartTempQline = QLineEdit()
self.StartTempQline.setPlaceholderText("Please Enter Start Temperature in Celsius")
self.FinalTempLabel = QLabel("Final Temperature")
self.FinalTempLabel.setStyleSheet('font-size: 12pt; font-family: arial,sans-serif')
self.FinalTempQline = QLineEdit()
self.FinalTempQline.setPlaceholderText("Please Enter Final Temperature in Celsius")
self.HeatingTimeLabel = QLabel("Heating Time")
self.HeatingTimeLabel.setStyleSheet('font-size: 12pt; font-family: arial,sans-serif')
self.HeatingTimeQline = QLineEdit()
self.HeatingTimeQline.setPlaceholderText("Please Enter Heating Time in Secs")
def layouts(self):
#####LAYOUTS#########
self.mainLayout = QHBoxLayout()
self.billetLayout = QFormLayout()
self.slabLayout = QFormLayout()
self.hollowLayout = QFormLayout()
###ADDING CHILD LAYOUTS TO MAIN LAYOUTS######
self.mainLayout.addLayout(self.billetLayout,350)
self.mainLayout.addLayout(self.slabLayout,350)
self.mainLayout.addLayout(self.hollowLayout,350)
###CALCULATION BUTTON WIDGETS###
self.billetLayout.addRow(self.Title)
self.billetLayout.addRow(self.DiameterLabel, self.DiameterQline)
self.billetLayout.addRow(self.HeightLabel, self.HeightQline)
self.billetLayout.addRow(self.StartTempLabel, self.StartTempQline)
self.billetLayout.addRow(self.FinalTempLabel, self.FinalTempQline)
self.billetLayout.addRow(self.HeatingTimeLabel, self.HeatingTimeQline)
self.billetLayout.addRow(self.buttonCalcBillet)
###ADDING WIDGETS TO CUSTOMER INFORMATION###
####SETTING MAIN LAYOUT###
self.setLayout(self.mainLayout)
def billetCalculationResults(self):
self.billetCalculation = BilletCalculationResults()
self.GetValues()
self.close()
def GetValues(self):
self.Diameter = float(self.DiameterQline.text())
self.Height = float(self.HeightQline.text())
self.StartTemp = float(self.StartTempQline.text())
self.FinalTemp = float(self.FinalTempQline.text())
self.HeatingTime = float(self.HeatingTimeQline.text())
class BilletCalculationResults(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Calculation Results")
self.setGeometry(450,150,350,600)
####CONSTRUCTION OF THE FIRST BILLET CLASS ###
self.UI()
self.show()
def UI(self):
self.billetCalculationPageDesign()
self.billetCalculationLayouts()
def billetCalculationPageDesign(self):
### BILLET RESULTS OF CALCULATION PAGE DESIGN ###
self.billetCalSurfaceAreaLabel = QLabel("Surface Area : ")
self.billetCalSurfaceAreaLabel.setStyleSheet('font-size: 12pt; font-family: arial,sans-serif')
str = "a"
self.billetCalSurfaceAreaLabelResult = QLabel(str)
self.billetCalSurfaceAreaLabelResult.setStyleSheet('font-size: 12pt; font-family: arial,sans-serif')
####VOLUME####
self.billetCalVolumeLabel = QLabel("Volume : ")
self.billetCalVolumeLabel.setStyleSheet('font-size: 12pt; font-family: arial,sans-serif')
self.billetCalVolumeLabelResult = QLabel("")
self.billetCalVolumeLabelResult.setStyleSheet('font-size: 12pt; font-family: arial,sans-serif')
def billetCalculationLayouts(self):
## BILLET RESULTS OF CALCULATION PAGE DESIGN ###
self.billetMainLayout = QFormLayout()
self.billetMainLayout.addRow(self.billetCalSurfaceAreaLabel,self.billetCalSurfaceAreaLabelResult)
self.billetMainLayout.addRow(self.billetCalVolumeLabel,self.billetCalVolumeLabelResult)
self.setLayout(self.billetMainLayout)
def main():
APP = QApplication(sys.argv)
window = Main()
sys.exit(APP.exec())
if __name__== '__main__':
main()
Solution
You almost had it, just get the values EDIT(1)
and add them to the constructor of your second window classEDIT(2)
. You can also save them to variables, but as an example I printed the values to the comand line Edit(3)
.
...
def billetCalculationResults(self):
self.GetValues() # EDIT(1) by Shraft
self.billetCalculation = BilletCalculationResults(self.Diameter, # EDIT
self.Height,self.StartTemp,self.FinalTemp,self.HeatingTime) # EDIT
self.close() # EDIT
def GetValues(self):
self.Diameter = float(self.DiameterQline.text())
self.Height = float(self.HeightQline.text())
self.StartTemp = float(self.StartTempQline.text())
self.FinalTemp = float(self.FinalTempQline.text())
self.HeatingTime = float(self.HeatingTimeQline.text())
class BilletCalculationResults(QWidget):
def __init__(self, diameter, height, startTemp, finalTemp, heatingTime): # EDIT(2) by Shraft
super().__init__()
print(diameter) # EDIT(3) by Shraft
print(height) # EDIT
print(startTemp) # EDIT
print(finalTemp) # EDIT
print(heatingTime) # EDIT
self.setWindowTitle("Calculation Results")
self.setGeometry(450,150,350,600)
####CONSTRUCTION OF THE FIRST BILLET CLASS ###
self.UI()
self.show()
...
Hope that helps you, are there more troubles let me know.
Answered By - Shraft
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.