Passing Variables

Joined
Dec 1, 2009
Messages
2
Reaction score
0
Hello I have developed code that makes fairly basic calculations and then prints them out accordingly on a frame.

But I want to know how to export these calculated variables for use in another frame.

import wx
import FloatSpin as FS

class DesignConditions(wx.Frame):

def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Design Conditions',size=(1000,700))
panel = wx.Panel(self)

wx.StaticText(panel,-1,'Atmospheric Temperature (K): ', (25,150))
wx.StaticText(panel,-1,'Atmospheric Pressure (kPa): ', (25,200))
wx.StaticText(panel,-1,'Mach Number: ', (25,250))
wx.StaticText(panel,-1,'Ratio of Specific Heat Capacities (k) of AIR: ', (25,300))
wx.StaticText(panel,-1,'Ratio of Specific Heat Capacities (k) of EXHAUST: ', (25,350))
wx.StaticText(panel,-1,'Gas co-efficient Constant (R - KJ/kg.K) of AIR: ', (25,400))
wx.StaticText(panel,-1,'Gas co-efficient Constant (R - KJ/kg.K) of EXHAUST: ', (25,450))

self.temp = FS.FloatSpin(panel,-1,min_val=200,max_val=300,increment=0.01,value=0.01,pos=(200,150))
self.temp.SetFormat("%f")
self.temp.SetDigits(3)

self.pres = FS.FloatSpin(panel,-1,min_val=10,max_val=110,increment=0.01,value=0.01,pos=(200,200))
self.pres.SetFormat("%f")
self.pres.SetDigits(3)

self.mach = FS.FloatSpin(panel,-1,min_val=0,max_val=10,increment=0.01,value=0.01,pos=(200,250))
self.mach.SetFormat("%f")
self.mach.SetDigits(3)

self.K = FS.FloatSpin(panel,-1,min_val=1,max_val=3,increment=0.01,value=1.4,pos=(275,300))
self.K.SetFormat("%f")
self.K.SetDigits(3)

self.Kt = FS.FloatSpin(panel,-1,min_val=1,max_val=3,increment=0.01,value=1.3,pos=(275,350))
self.Kt.SetFormat("%f")
self.Kt.SetDigits(3)

self.R = FS.FloatSpin(panel,-1,min_val=0,max_val=1,increment=0.01,value=0.287,pos=(275,400))
self.R.SetFormat("%f")
self.R.SetDigits(3)

self.Rt = FS.FloatSpin(panel,-1,min_val=0,max_val=1,increment=0.01,value=0.287,pos=(285,450))
self.Rt.SetFormat("%f")
self.Rt.SetDigits(3)

wx.StaticText(panel,-1,'Stagnation Temperature: ', (350,150))
wx.StaticText(panel,-1,'Stagnation Pressure: ', (350,200))
wx.StaticText(panel,-1,'Speed of Sound: ', (350,250))
wx.StaticText(panel,-1,'Specific Heat Capacity of AIR @ Constant Pressure: ', (450,300))
wx.StaticText(panel,-1,'Specific Heat Capacity of EXHAUST @ Constant Pressure: ', (450,350))

self.t2 = wx.StaticText(panel,-1,'',(500,150))
self.p2 = wx.StaticText(panel,-1,'',(500,200))
self.speed = wx.StaticText(panel,-1,'',(500,250))
self.cp = wx.StaticText(panel,-1,'',(710,300))
self.cpe = wx.StaticText(panel,-1,'',(750,350))

compute_btn = wx.Button(panel,1,'Calculate',(450,450))
compute_btn.SetFocus()
clear_btn = wx.Button(panel,2,'Quit',(650,450))

wx.EVT_BUTTON(panel,1,self.OnCompute)
wx.EVT_BUTTON(panel,2,self.OnClose)
wx.EVT_CLOSE(panel,self.OnClose)

def OnCompute(self,event):

t = float(self.temp.GetValue())
p = float(self.pres.GetValue())
M = float(self.mach.GetValue())
k = float(self.K.GetValue())
kt = float(self.Kt.GetValue())
R = float(self.R.GetValue())
Rt = float(self.Rt.GetValue())

t2 = t*(1+((k-1)/2)*(M**2))
p2 = p*((1+((k-1)/2)**(M**2))**((k-1)/k))
v = (1000*k*R*t)**(0.5)
cp = (k*R)/(k - 1)
cpe = (kt*Rt)/(kt - 1)

self.t2.SetLabel(str(t2) + ' K')
self.p2.SetLabel(str(p2) + ' kPa')
self.speed.SetLabel(str(v) + ' m/s')
self.cp.SetLabel(str(cp) + ' KJ/kg.K')
self.cpe.SetLabel(str(cpe) + ' KJ/kg.K')

return t2,p2,v,k,kt,cp,cpe

def OnClose(self,event):
self.Destroy()

if __name__=='__main__':

app = wx.PySimpleApp()
frame = DesignConditions(parent=None, id=1)
frame.Show()
app.MainLoop()

Basically all i want to do is export t2,p2,v,k,kt,cp,cpe for use in another file...

Its a very basic question because I am an absolute newb at wxPython and Python programming.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top