miércoles, 15 de junio de 2022

Tkinter Tensión Interfacial Gas-Petróleo

Ahora se elabora la interfaz gráfica de la tensión interfacial del gas-petróleo, en seguida 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("590x200")
Ventana.maxsize(590,200)
Ventana.minsize(590,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)
 
 
def Correlaciones_Tension_Petroleo():
 
            try:
 
                        #YAPI = 31
                        #T = 194
                        #P = 3000
 
                        P   = float(Entrada_1.get()) # psi
                        T   = float(Entrada_2.get()) # °F
                        API = float(Entrada_3.get()) # °API  
 
                        if P <= 0:
 
                                   messagebox.showwarning("Advertencia!","La Presión es incorrecta")
 
                        elif T <= 0:
 
                                   messagebox.showwarning("Advertencia!","La Temperatura es incorrecta")
 
                        elif API <= 0:
 
                                   messagebox.showwarning("Advertencia!","La Gravedad API es incorrecta")
 
                        else:
 
                                   Yo = 141.5/(API + 131.5)
                         
                                   σ68 = 39-0.2571*API
                                   σ100 = 37.5-0.2571*API
                                   σT = σ68-((T-68)*(σ68-σ100))/32
 
                                   Fc= 1.0-0.024*P**0.45
 
                                   σgo  = Fc*σT
 
                                   Salida_1.delete(0,tk.END);Salida_1.insert(tk.END,σ68)
                                   Salida_2.delete(0,tk.END);Salida_2.insert(tk.END,σ100)
                                   Salida_3.delete(0,tk.END);Salida_3.insert(tk.END,σT)
                                   Salida_4.delete(0,tk.END);Salida_4.insert(tk.END,σgo)
                       
            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
 
Densidad_Petróleo = Button(Recuadro_Entradas,activebackground="DarkOrange3",activeforeground="black",background="gray80",disabledforeground="#a3a3a3",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",pady="0",text='''Densidad del Petróleo''', command = Correlaciones_Tension_Petroleo).place(relx = 0.013, rely = 0.65, height=25, width=170,bordermode='ignore')
 
Mensaje_1 = tk.Message(Recuadro_Entradas)
Mensaje_1.place(relx=0.02, rely=0.05, height=25, width=80)
Mensaje_1.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''P''')
Mensaje_2 = tk.Message(Recuadro_Entradas)
Mensaje_2.place(relx=0.02, rely=0.23, height=25, width=80)
Mensaje_2.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''T''')
Mensaje_3 = tk.Message(Recuadro_Entradas)
Mensaje_3.place(relx=0.02, rely=0.41, height=25, width=80)
Mensaje_3.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''API''')
 
Mensaje_4 = tk.Label(Recuadro_Entradas)
Mensaje_4.place(relx=0.32, rely=0.05, height=25, width=210)
Mensaje_4.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''Resultado:''')
Mensaje_5 = tk.Label(Recuadro_Entradas)
Mensaje_5.place(relx=0.32, rely=0.23, height=25, width=210)
Mensaje_5.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='left',text='''Tensión interfacial a 68 °F''')
Mensaje_6 = tk.Label(Recuadro_Entradas)
Mensaje_6.place(relx=0.32, rely=0.41, height=25, width=210)
Mensaje_6.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='left',text='''Tensión interfacial a 100 °F''')
Mensaje_7 = tk.Label(Recuadro_Entradas)
Mensaje_7.place(relx=0.32, rely=0.59, height=25, width=210)
Mensaje_7.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='left',text='''Tensión interfacial''')
Mensaje_8 = tk.Label(Recuadro_Entradas)
Mensaje_8.place(relx=0.32, rely=0.77, height=25, width=210)
Mensaje_8.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='left',text='''Tensión interfacial a cualquier presión''')
 
Mensaje_9 = tk.Label(Recuadro_Entradas)
Mensaje_9.place(relx = 0.90, rely = 0.25, height=25, width=50)
Mensaje_9.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''dinas/cm''')
Mensaje_10 = tk.Label(Recuadro_Entradas)
Mensaje_10.place(relx = 0.90, rely = 0.43, height=25, width=50)
Mensaje_10.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''dinas/cm''')
Mensaje_11 = tk.Label(Recuadro_Entradas)
Mensaje_11.place(relx = 0.90, rely = 0.61, height=25, width=50)
Mensaje_11.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''dinas/cm''')
Mensaje_12 = tk.Label(Recuadro_Entradas)
Mensaje_12.place(relx = 0.90, rely = 0.79, height=25, width=50)
Mensaje_12.configure(background="gray80",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center',text='''dinas/cm''')
 
 
Entrada_1 = tk.Entry(Recuadro_Entradas)
Entrada_1.place(relx=0.17, rely=0.07, 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.17, rely=0.25, 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.17, rely=0.43, 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.705, rely=0.25, height=20, width=100)
Salida_1.configure(background="white",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center')
Salida_2 = tk.Entry(Recuadro_Entradas)
Salida_2.place(relx=0.705, rely=0.43, height=20, width=100)
Salida_2.configure(background="white",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center')
Salida_3 = tk.Entry(Recuadro_Entradas)
Salida_3.place(relx=0.705, rely=0.61, height=20, width=100)
Salida_3.configure(background="white",foreground="#000000",highlightbackground="#d9d9d9",highlightcolor="black",justify='center')
Salida_4 = tk.Entry(Recuadro_Entradas)
Salida_4.place(relx=0.705, rely=0.79, height=20, width=100)
Salida_4.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)
Salida_2.delete(0,tk.END);Salida_2.insert(tk.END,"");Salida_2.insert(tk.END,0.00)
Salida_3.delete(0,tk.END);Salida_3.insert(tk.END,"");Salida_3.insert(tk.END,0.00)
Salida_4.delete(0,tk.END);Salida_4.insert(tk.END,"");Salida_4.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)
            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)
            Salida_2.delete(0,tk.END);Salida_2.insert(tk.END,"");Salida_2.insert(tk.END,0.00)
            Salida_3.delete(0,tk.END);Salida_3.insert(tk.END,"");Salida_3.insert(tk.END,0.00)
            Salida_4.delete(0,tk.END);Salida_4.insert(tk.END,"");Salida_4.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=170)
 
Ventana.mainloop()
 
El código de vuelve lo siguiente:



No hay comentarios.:

Publicar un comentario