Continuando con la creación de interfaces gráficas, se trae
en esta ocasión la relación gas disuelto-agua, la interfaz cuenta con 2
correlaciones que permiten la obtención
de Rsw, A continuación se muestra el código completo:
import math as math
from tkinter import *
import tkinter as tk
from tkinter import ttk
import numpy as np
from tkinter import messagebox
Ventana = Tk()
Ventana.geometry("300x200")
Ventana.maxsize(300,200)
Ventana.minsize(300,200)
Ventana.title("Tensión Interfacial del Petróleo")
Ventana.configure(background="gray80",highlightbackground="gray80",highlightcolor="black")
Recuadro_Entradas = tk.LabelFrame(Ventana)
Recuadro_Entradas.place(relx=0.01, rely=0.01, relheight=0.980, relwidth=0.980)
Recuadro_Entradas.configure(relief='groove',foreground="black",text='''Entradas''',background="gray80",highlightbackground="gray80",highlightcolor="black",width=330)
Valores = ["Culberson, O.L y McKetta, J.J.,
Jr.","McCoy, R.L"]
Variable = tk.StringVar()
Visor_correlaciones = ttk.Combobox(Recuadro_Entradas)
Visor_correlaciones.place(relx=0.02, rely=0.12, height=25, width=280, bordermode='ignore')
Visor_correlaciones.configure(takefocus="",state="readonly",textvariable = Variable, justify = "center",values = Valores)
Visor_correlaciones.current(0)
def Correlaciones_RSW(event):
try:
#
S = 20000/10000 # ppm
# P = 5000 # psi
# T = 200 # °F
S
= float(Entrada_1.get()) # psi
P = float(Entrada_2.get()) # °F
T = float(Entrada_3.get()) # °S
if
P <= 0:
messagebox.showwarning("Advertencia!","La
Salinidad es incorrecta")
elif
T <= 0:
messagebox.showwarning("Advertencia!","La
Presión es incorrecta")
elif
S <= 0:
messagebox.showwarning("Advertencia!","La
Temperatura es incorrecta")
else:
S
= S/10000
if
str(Variable.get()) == Valores[0]:
#
Correlación de Culberson, O.L y McKetta, J.J., Jr.
A
= 8.15839-(6.12265*(10**(-2) )*T)+(1.91663*(10**(-4) )*(T**2
))-(2.1654*(10**(-7) )*(T**3 ))
B = (1.01021*(10**(-2) ))-(7.44241*(10**(-5) )*T)+(3.05553*(10**(-7) )*(T**2 ))-(2.94883*(10**(-10) )*(T**3 ))
C = (-9.02505+(0.130237*T)-(8.53425*(10**(-4) )*(T**2 ))+(2.34122*(10**(-6) )*(T**3 ))-(2.37049*(10**(-9) )*(T**4 )))*(10**(-7) )
Rswp
= A+B*P+C*P**2
#
Corrección por salinidad dentro de los rangos 0<Salinidad(%)<30 y
70<Temperatura(°F)<250
Rsw
= (10**(-0.0840655*S*(T**-0.285854)))*Rswp
Salida_1.delete(0,tk.END);Salida_1.insert(tk.END,Rsw)
elif
str(Variable.get()) == Valores[1]:
#
Correlación de McCoy, R.L
A =
2.12+3.45*(10**-3)*T-3.59*(10**-5)*(T**2)
B = 0.0107-5.26*(10**-5)*T+1.48*(10**-7)*(T**2)
C = -8.75*(10**-7)+3.9*(10**-9)*T-1.02*(10**-11)*(T**2)
Rswp=
A+B*P+C*P**2
#
Rsw
= (1-(0.0753-(1.73*10**-4)*T)*S)*Rswp
Salida_1.delete(0,tk.END);Salida_1.insert(tk.END,Rsw)
else:
print("Error
al realizar la selección de la opción")
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
Visor_correlaciones.bind('<<ComboboxSelected>>',
Correlaciones_RSW)
Mensaje_1 = tk.Message(Recuadro_Entradas)
Mensaje_1.place(relx=0.01, rely=0.20, height=25, width=50)
Mensaje_1.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''S''')
Mensaje_2 = tk.Message(Recuadro_Entradas)
Mensaje_2.place(relx=0.01, rely=0.40, height=25, width=50)
Mensaje_2.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''P''')
Mensaje_3 = tk.Message(Recuadro_Entradas)
Mensaje_3.place(relx=0.01, rely=0.60, height=25, width=50)
Mensaje_3.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''T''')
Mensaje_4 = tk.Label(Recuadro_Entradas)
Mensaje_4.place(relx=0.45, rely=0.20, height=25, width=80)
Mensaje_4.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='left',text='''RSW''')
Mensaje_9 = tk.Label(Recuadro_Entradas)
Mensaje_9.place(relx = 0.75, rely = 0.35, height=25, width=50)
Mensaje_9.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''PCN/BN''')
Entrada_1 = tk.Entry(Recuadro_Entradas)
Entrada_1.place(relx=0.2, rely=0.21, 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.2, rely=0.41, 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.2, rely=0.61, height=20, width=80)
Entrada_3.configure(background="white",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center')
Salida_1 = tk.Entry(Recuadro_Entradas)
Salida_1.place(relx=0.7, rely=0.21, height=20, width=80)
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)
Salida_1.delete(0,tk.END);Salida_1.insert(tk.END,"");Salida_1.insert(tk.END,0.00)
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)
Salida_1.delete(0,tk.END);Salida_1.insert(tk.END,"");Salida_1.insert(tk.END,0.00)
return
Limpieza =
Button(Recuadro_Entradas,activebackground="OliveDrab4",activeforeground="black",background="gray80",disabledforeground="#a3a3a3",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",pady="0",text='''Limpieza''',
command = Limpiando).place(relx = 0.01, rely = 0.80, height=25, width=280)
Ventana.mainloop()
El código devuelve lo siguiente:
from tkinter import *
import tkinter as tk
from tkinter import ttk
import numpy as np
from tkinter import messagebox
Ventana.geometry("300x200")
Ventana.maxsize(300,200)
Ventana.minsize(300,200)
Ventana.title("Tensión Interfacial del Petróleo")
Ventana.configure(background="gray80",highlightbackground="gray80",highlightcolor="black")
Recuadro_Entradas.place(relx=0.01, rely=0.01, relheight=0.980, relwidth=0.980)
Recuadro_Entradas.configure(relief='groove',foreground="black",text='''Entradas''',background="gray80",highlightbackground="gray80",highlightcolor="black",width=330)
Visor_correlaciones = ttk.Combobox(Recuadro_Entradas)
Visor_correlaciones.place(relx=0.02, rely=0.12, height=25, width=280, bordermode='ignore')
Visor_correlaciones.configure(takefocus="",state="readonly",textvariable = Variable, justify = "center",values = Valores)
Visor_correlaciones.current(0)
# P = 5000 # psi
# T = 200 # °F
P = float(Entrada_2.get()) # °F
T = float(Entrada_3.get()) # °S
B = (1.01021*(10**(-2) ))-(7.44241*(10**(-5) )*T)+(3.05553*(10**(-7) )*(T**2 ))-(2.94883*(10**(-10) )*(T**3 ))
C = (-9.02505+(0.130237*T)-(8.53425*(10**(-4) )*(T**2 ))+(2.34122*(10**(-6) )*(T**3 ))-(2.37049*(10**(-9) )*(T**4 )))*(10**(-7) )
B = 0.0107-5.26*(10**-5)*T+1.48*(10**-7)*(T**2)
C = -8.75*(10**-7)+3.9*(10**-9)*T-1.02*(10**-11)*(T**2)
except ZeroDivisionError:
Mensaje_1.place(relx=0.01, rely=0.20, height=25, width=50)
Mensaje_1.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''S''')
Mensaje_2 = tk.Message(Recuadro_Entradas)
Mensaje_2.place(relx=0.01, rely=0.40, height=25, width=50)
Mensaje_2.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''P''')
Mensaje_3 = tk.Message(Recuadro_Entradas)
Mensaje_3.place(relx=0.01, rely=0.60, height=25, width=50)
Mensaje_3.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''T''')
Mensaje_4.place(relx=0.45, rely=0.20, height=25, width=80)
Mensaje_4.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='left',text='''RSW''')
Mensaje_9 = tk.Label(Recuadro_Entradas)
Mensaje_9.place(relx = 0.75, rely = 0.35, height=25, width=50)
Mensaje_9.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''PCN/BN''')
Entrada_1.place(relx=0.2, rely=0.21, 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.2, rely=0.41, 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.2, rely=0.61, height=20, width=80)
Entrada_3.configure(background="white",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center')
Salida_1 = tk.Entry(Recuadro_Entradas)
Salida_1.place(relx=0.7, rely=0.21, height=20, width=80)
Salida_1.configure(background="white",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center')
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)
Salida_1.delete(0,tk.END);Salida_1.insert(tk.END,"");Salida_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)
Salida_1.delete(0,tk.END);Salida_1.insert(tk.END,"");Salida_1.insert(tk.END,0.00)
El código devuelve lo siguiente:

No hay comentarios.:
Publicar un comentario