Se trae a continuación la interfaz gráfica de las correlaciones de la compresibilidad del gas. En este código se hace uso de los radiobuttons los cuales se aprecian en la siguiente imagen.
Ahora se muestra el código del radiobutton,
este contiene muchos atributos que ya se han revisado, por lo que en esta
ocasión se hablará sólo de los nuevos atributos.
Boton_Mattar = tk.Radiobutton(Sexta_Ventana,text='''Mattar, L., Brar, G.S. y Aziz, K.''',variable= var,value="1",command = Compresibilidad_Gas.Mattar,background="gray80",activebackground="blue").place(relx = 0.01, rely = 0.02, height=30, width=210,bordermode='ignore')
Como se aprecia los atributos que han sido agregados son:
·
Variable – Esta recibe una variable la cual indica
el valor de inicio del radiobutton
·
Value - Asigna
un valor al radiobutton en este caso recibe el valor 1
En seguida se
muestra el código completo.
import math as math
from tkinter import *
import tkinter as tk
import numpy as np
from tkinter import messagebox
Sexta_Ventana = Tk()
Sexta_Ventana.geometry("450x200")
Sexta_Ventana.maxsize(450,200)
Sexta_Ventana.minsize(450,200)
Sexta_Ventana.title("Compresibilidad
del Gas")
Sexta_Ventana.configure(background="gray80",highlightbackground="gray80",highlightcolor="black")
var = StringVar(Sexta_Ventana,"1")
class Compresibilidad_Gas():
def
Mattar():
#
Mattar, L., Brar,G.S. y Aziz, K.
try:
z
= float(Entrada_4.get())
Pr
= float(Entrada_3.get())
Tpr
= float(Entrada_1.get())
Ppr
= float(Entrada_2.get())
if
z <= 0:
messagebox.showwarning("Advertencia!","El
Factor de compresibilidad es incorrecto")
elif
Pr <= 0:
messagebox.showwarning("Advertencia!","La
Presión reducida es incorrecta")
elif
Tpr <= 0:
messagebox.showwarning("Advertencia!","La
Temperatura pseudoreducida es incorrecta")
elif
Ppr <= 0:
messagebox.showwarning("Advertencia!","La
Presión pseudoreducida es incorrecta")
else:
A1
= 0.31506237
A2
= -1.0467099
A3
= -0.57832729
A4
= 0.53530771
A5
= -0.61232032
A6
= -0.10488813
A7
= 0.68157001
A8
= 0.68446549
Delta =
A1+(A2/Tpr)+(A3/(Tpr**3))+2*(A4+(A5/Tpr))*Pr+5*A5*A6*(Pr**4/Tpr)+((2*A7*Pr)/(Tpr**3))*(1+(A8*Pr**2)-(A8*Pr**2)**2)*math.exp(-A8*Pr**2)
Cr
= (1/Ppr)-(0.27/((z**2)*Tpr))*(Delta/(1+(Pr/z)*Delta))
Cg1
= Cr/680
Salida_1.delete(0,tk.END)
Salida_1.insert(tk.END,round(Cg1,7))
except
ZeroDivisionError:
messagebox.showwarning("Advertencia!","Los
datos ingresados son incorrectos, por favor revisalos")
except
SyntaxError:
messagebox.showwarning("Advertencia!","Los
datos ingresados son incorrectos, por favor revisalos")
except
ValueError:
messagebox.showwarning("Advertencia!","Los
datos ingresados son incorrectos, por favor revisalos")
finally:
pass
return
def
Sarem():
#
Sarem, A.M.
try:
z
= float(Entrada_4.get())
Pr
= float(Entrada_3.get())
Tpr
= float(Entrada_1.get())
Ppr
= float(Entrada_2.get())
if
z <= 0:
messagebox.showwarning("Advertencia!","El
Factor de compresibilidad es incorrecto")
elif
Pr <= 0:
messagebox.showwarning("Advertencia!","La
Presión reducida es incorrecta")
elif
Tpr <= 0:
messagebox.showwarning("Advertencia!","La
Temperatura pseudoreducida es incorrecta")
elif
Ppr <= 0:
messagebox.showwarning("Advertencia!","La
Presión pseudoreducida es incorrecta")
else:
X
= -0.257
Y
= -0.684
MM
=
np.array([[2.1434,0.0832,-0.0215,-0.0009,0.0043,-0.0017],[0.3313,-0.1340,0.0669,-0.0272,0.0089,-0.0022],[0.1057,-0.0504,0.0051,0.0106,-0.0073,0.0027],[0.0522,0.0443,-0.0193,0.0059,0.0015,-0.0028],[0.0197,-0.0264,0.0193,-0.0115,0.0043,-0.0081],[0.0053,0.0089,-0.0109,0.0096,-0.0060,0.0031]])
PX0
= np.array([[0],[0.16551],[0.641002*X],[0.379221*(5*(X**2)-1)],[0.716652*(7*(X**3)-3*X)],[0.594225*(21*(X**4)-14*(X**2)+1)]])
PY0
= np.array([[0.7071068],[1.224745*Y
],[0.7905695*(3*(Y**2)-1)],[0.9354145*(5*(Y**3)-3*Y)],[0.265165*(35*(Y**4)-30*(Y**2)+3)],[0.293151*(63*(Y**5)-70*(Y**3)+15*Y)]])
Delta
= 0
for
i in np.arange(0,6):
for
j in np.arange(0,6):
Delta
= Delta+MM[i][j]*PX0[i]*PY0[j]
Cr
= (1/Ppr)-(Delta/z)
Cg2
= Cr/680
Salida_1.delete(0,tk.END)
Salida_1.insert(tk.END,round(float(Cg2),7))
except
ZeroDivisionError:
messagebox.showwarning("Advertencia!","Los
datos ingresados son incorrectos por favor revisalos")
except
SyntaxError:
messagebox.showwarning("Advertencia!","Los
datos ingresados son incorrectos, por favor revisalos")
except
ValueError:
messagebox.showwarning("Advertencia!","Los
datos ingresados son incorrectos, por favor revisalos")
finally:
pass
return
def
Papay():
#
Papay, J.
try:
z
= float(Entrada_4.get())
Pr
= float(Entrada_3.get())
Tpr
= float(Entrada_1.get())
Ppr
= float(Entrada_2.get())
if
z <= 0:
messagebox.showwarning("Advertencia!","El
Factor de compresibilidad es incorrecto")
elif
Pr <= 0:
messagebox.showwarning("Advertencia!","La
Presión reducida es incorrecta")
elif
Tpr <= 0:
messagebox.showwarning("Advertencia!","La
Temperatura pseudoreducida es incorrecta")
elif
Ppr <= 0:
messagebox.showwarning("Advertencia!","La
Presión pseudoreducida es incorrecta")
else:
Delta
= -(3.52/(10**(0.9812*Tpr)))+((0.548*Ppr)/(10**(0.8157*Tpr)))
Cr
= (1/Ppr)-(Delta/z)
Cg3
= Cr/680
Salida_1.delete(0,tk.END)
Salida_1.insert(tk.END,round(float(Cg3),7))
except
ZeroDivisionError:
messagebox.showwarning("Advertencia!","Los
datos ingresados son incorrectos por favor revisalos")
except
SyntaxError:
messagebox.showwarning("Advertencia!","Los
datos ingresados son incorrectos, por favor revisalos")
except
ValueError:
messagebox.showwarning("Advertencia!","Los
datos ingresados son incorrectos, por favor revisalos")
finally:
pass
return
def
Hall():
#
Hall, K.R. y Yarborough, L.
try:
z
= float(Entrada_4.get())
Pr
= float(Entrada_3.get())
Tpr
= float(Entrada_1.get())
Ppr
= float(Entrada_2.get())
if
z <= 0:
messagebox.showwarning("Advertencia!","El
Factor de compresibilidad es incorrecto")
elif
Pr <= 0:
messagebox.showwarning("Advertencia!","La
Presión reducida es incorrecta")
elif
Tpr <= 0:
messagebox.showwarning("Advertencia!","La
Temperatura pseudoreducida es incorrecta")
elif
Ppr <= 0:
messagebox.showwarning("Advertencia!","La
Presión pseudoreducida es incorrecta")
else:
t
= 485/(194+460)# Tpc/T
def
DDF(Y,t):
A
= 0.06125*t*np.exp(-1.2*(1-t)**2)
B
= (14.76*t-9.76*t**2+4.58*t**3)
C
= (90.7*t-242.2*t**2+42.4*t**3)
D
= 2.18+2.82*t
Y
= -A*Ppr+((Y+(Y**2)+(Y**3)-(Y**4))/((1-Y)**3))-B*(Y**2)+C*(Y**D)
return
Y
Y
= 0.01
conteo
= 0
error
= 1
while
error > 0.00000001:
dy
= ((DDF(Y,t)+0.0001)-DDF(Y,t))/0.0001
yn
= Y-DDF(Y,t)/dy
conteo
= conteo + 1
error
= (yn-Y)/yn
Y
= yn
A
= 0.06125*t*math.exp(-1.2*(1-t)**2)
B
= 14.76*t-9.76*t**2+4.58*t**3
C
= 90.7*t-242.2*t**2+42.4*t**3
D
= 2.18+2.82*t
z
= (A*Ppr)/Y
Delta
=
A*(((1-Y)**4)/(1+(4*Y)+(4*(Y**2))-(4*(Y**3))+(Y**4)-((1-Y)**4)*((2*B*Y)-C*D*Y**(D-1))))
Delta
= (A/Y)-(A*Ppr)/(Y**2)*(Delta)
Cr
= (1/Ppr)-(Delta/z)
Cg4
= Cr/680
Salida_1.delete(0,tk.END)
Salida_1.insert(tk.END,round(float(Cg4),7))
except
ZeroDivisionError:
messagebox.showwarning("Advertencia!","Los
datos ingresados son incorrectos por favor revisalos")
except
SyntaxError:
messagebox.showwarning("Advertencia!","Los
datos ingresados son incorrectos, por favor revisalos")
except
ValueError:
messagebox.showwarning("Advertencia!","Los
datos ingresados son incorrectos, por favor revisalos")
finally:
pass
return
def
Brill():
#
Brill, J.P. y Beggs, H.D.
try:
z
= float(Entrada_4.get())
Pr
= float(Entrada_3.get())
Tpr
= float(Entrada_1.get())
Ppr
= float(Entrada_2.get())
if
z <= 0:
messagebox.showwarning("Advertencia!","El
Factor de compresibilidad es incorrecto")
elif
Pr <= 0:
messagebox.showwarning("Advertencia!","La
Presión reducida es incorrecta")
elif
Tpr <= 0:
messagebox.showwarning("Advertencia!","La
Temperatura pseudoreducida es incorrecta")
elif
Ppr <= 0:
messagebox.showwarning("Advertencia!","La
Presión pseudoreducida es incorrecta")
else:
F
= 0.3106 - (0.49*(Tpr)) + (0.1824*(Tpr)**2)
E
= 9*(Tpr-1)
D
= 10**F
C
= 0.132-0.32*np.log10(Tpr)
B
= (0.62-(0.23*Tpr))*Ppr + ((0.066/(Tpr-0.86))-0.037)*(Ppr**2) +
(0.32/(10**E))*(Ppr**6)
A
= (1.39*(Tpr-0.92)**0.5)-(0.36*Tpr)-0.10
z
= A + ((1-A)/np.exp(B)) + (C*(Ppr**D))
Delta
=
((1-A)/(((0.62-0.23*Tpr)+(((0.132/(Tpr-0.86))-0.74)*Ppr)+((1.92*Ppr**5)/10**(9*(Tpr-1))))+np.exp(B)))+C*D*(Ppr**(D-1))
Cr
= (1/Ppr)-(Delta/z)
Cg5
= Cr/680
Salida_1.delete(0,tk.END)
Salida_1.insert(tk.END,round(float(Cg5),7))
except
ZeroDivisionError:
messagebox.showwarning("Advertencia!","Los
datos ingresados son incorrectos por favor revisalos")
except
SyntaxError:
messagebox.showwarning("Advertencia!","Los
datos ingresados son incorrectos, por favor revisalos")
except
ValueError:
messagebox.showwarning("Advertencia!","Los
datos ingresados son incorrectos, por favor revisalos")
finally:
pass
return
Boton_Mattar =
tk.Radiobutton(Sexta_Ventana,text='''Mattar, L., Brar, G.S. y Aziz,
K.''',variable= var,value="1",command =
Compresibilidad_Gas.Mattar,background="gray80",activebackground="blue").place(relx
= 0.01, rely = 0.02, height=30, width=210,bordermode='ignore')
Boton_Sarem
= tk.Radiobutton(Sexta_Ventana,text='''Sarem,
A.M.''',variable=var,value="2",command = Compresibilidad_Gas.Sarem,
justify = "right",background="gray80",activebackground="purple").place(relx
= 0.01, rely = 0.18, height=30, width = 210,bordermode='ignore')
Boton_Papay =
tk.Radiobutton(Sexta_Ventana,text='''Papay, J.''',variable=
var,value="3",command =
Compresibilidad_Gas.Papay,background="gray80",activebackground="red").place(relx
= 0.01, rely = 0.34, height=30, width = 210,bordermode='ignore')
Boton_Hall =
tk.Radiobutton(Sexta_Ventana,text='''Hall, K.R. y Yarborough,
L.''',variable=var,value="4",command = Compresibilidad_Gas.Hall,
justify = "right",background="gray80",activebackground="orange").place(relx
= 0.01, rely = 0.50, height=30, width = 210,bordermode='ignore')
Boton_Brill
= tk.Radiobutton(Sexta_Ventana,text='''Brill, J.P. y Beggs,
H.D.''',variable=var,value="5",command = Compresibilidad_Gas.Brill,
justify =
"right",background="gray80",activebackground="yellow").place(relx
= 0.01, rely = 0.66, height=30, width=210,bordermode='ignore')
Recuadro_Entradas =
tk.LabelFrame(Sexta_Ventana)
Recuadro_Entradas.place(relx=0.49,
rely=0.01, relheight=0.970, relwidth=0.500)
Recuadro_Entradas.configure(relief='groove',foreground="black",text='''Entradas''',background="gray80",highlightbackground="gray80",highlightcolor="black",width=330)
Entrada_1 = tk.Entry(Recuadro_Entradas)
Entrada_1.place(relx=0.10, rely=0.15,
height=20, width=80)
Entrada_1.configure(background="white",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center')
Entrada_2 = tk.Entry(Recuadro_Entradas)
Entrada_2.place(relx=0.10, rely=0.43,
height=20, width=80)
Entrada_2.configure(background="white",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center')
Entrada_3 = tk.Entry(Recuadro_Entradas)
Entrada_3.place(relx=0.55, rely=0.15,
height=20, width=80)
Entrada_3.configure(background="white",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center')
Entrada_4 = tk.Entry(Recuadro_Entradas)
Entrada_4.place(relx=0.55, rely=0.43,
height=20, width=80)
Entrada_4.configure(background="white",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center')
Salida_1 = tk.Entry(Recuadro_Entradas)
Salida_1.place(relx=0.21, rely=0.71,
height=20, width=140)
Salida_1.configure(background="white",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center')
Entrada_1.delete(0,tk.END)
Entrada_1.insert(tk.END,"")
Entrada_1.insert(tk.END,0.00)
Entrada_2.delete(0,tk.END)
Entrada_2.insert(tk.END,"")
Entrada_2.insert(tk.END,0.00)
Entrada_3.delete(0,tk.END)
Entrada_3.insert(tk.END,"")
Entrada_3.insert(tk.END,0.00)
Entrada_4.delete(0,tk.END)
Entrada_4.insert(tk.END,"")
Entrada_4.insert(tk.END,0.00)
Salida_1.delete(0,tk.END)
Salida_1.insert(tk.END,"")
Salida_1.insert(tk.END,0.00)
Mensaje_1 = tk.Message(Recuadro_Entradas)
Mensaje_1.place(relx=0.10, rely=0.00,
height=25, width=80)
Mensaje_1.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''Tpr:''')
Mensaje_2 = tk.Message(Recuadro_Entradas)
Mensaje_2.place(relx=0.10, rely=0.28,
height=25, width=80)
Mensaje_2.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''Ppr:''')
Mensaje_1 = tk.Message(Recuadro_Entradas)
Mensaje_1.place(relx=0.55, rely=0.00,
height=25, width=80)
Mensaje_1.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''Pr:''')
Mensaje_2 = tk.Message(Recuadro_Entradas)
Mensaje_2.place(relx=0.55, rely=0.28,
height=25, width=80)
Mensaje_2.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''Z:''')
Mensaje_3 = tk.Label(Recuadro_Entradas)
Mensaje_3.place(relx=0.21, rely=0.56,
height=25, width=140)
Mensaje_3.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''Resultado:''')
def Limpiando():
Entrada_1.delete(0,tk.END)
Entrada_1.insert(tk.END,"")
Entrada_1.insert(tk.END,0.00)
Entrada_2.delete(0,tk.END)
Entrada_2.insert(tk.END,"")
Entrada_2.insert(tk.END,0.00)
Entrada_3.delete(0,tk.END)
Entrada_3.insert(tk.END,"")
Entrada_3.insert(tk.END,0.00)
Entrada_4.delete(0,tk.END)
Entrada_4.insert(tk.END,"")
Entrada_4.insert(tk.END,0.00)
Salida_1.delete(0,tk.END)
Salida_1.insert(tk.END,"")
Salida_1.insert(tk.END,0.00)
return
Limpieza =
Button(Recuadro_Entradas,activebackground="cyan",activeforeground="black",background="gray80",disabledforeground="#a3a3a3",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",pady="0",text='''Limpieza''',
command = Limpiando).place(relx = 0.01, rely = 0.85, height=25, width=217)
Sexta_Ventana.mainloop()
El código devuelve lo siguiente:
No hay comentarios.:
Publicar un comentario