Hace unos días atrás publicamos la
primera versión de programa de valoración de soluciones continuación les dejo la segunda versión, en esta hacemos uso de la librería tkinter.
el código fuente es el siguiente:
##Programa de valoracion de Soluciones vercion 2
#### usando la ecuancion C1V1 = C2V2
##### es necesario tener python 3.3 y la libreria tkinter
###### hecho por israel Nuñez
####### Universidad Autonoma Metropolitana
### isrant.blogspot.com
##### mexico D.F
from tkinter import*
from tkinter import messagebox
import math
def variables(e):
global cas
var = lb.curselection()
var1 = tuple(('0',))
var2 = tuple(('1',))
var3 = tuple (('2'))
var4 = tuple (('3'))
if var == var1:
##calculando C1
cas = 1
texto=Label(ventana,text='V2')
texto.place(bordermode = OUTSIDE, height=20, width =100, x = 300, y = 60)
texto = Label(ventana, text = "V1")
texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 100)
texto = Label(ventana, text = "C2")
texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 140)
textores2 = Label(ventana, text = "C1")
textores2.place(bordermode = OUTSIDE, height = 20, width = 150, x = 50, y = 250)
elif var == var2:
##calculando C2
cas = 2
texto=Label(ventana,text='V2')
texto.place(bordermode = OUTSIDE, height=20, width =100, x = 300, y = 60)
texto = Label(ventana, text = "V1")
texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 100)
texto = Label(ventana, text = "C1")
texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 140)
textores2 = Label(ventana, text = "C2")
textores2.place(bordermode = OUTSIDE, height = 20, width = 150, x = 50, y = 250)
elif var == var3:
cas = 3
##calculando V1
texto=Label(ventana,text='V2')
texto.place(bordermode = OUTSIDE, height=20, width =100, x = 300, y = 60)
texto = Label(ventana, text = "C1")
texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 100)
texto = Label(ventana, text = "C2")
texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 140)
textores2 = Label(ventana, text = "V1")
textores2.place(bordermode = OUTSIDE, height = 20, width = 150, x = 50, y = 250)
elif var ==var4:
cas = 4
##calculando V2
texto=Label(ventana,text='V1')
texto.place(bordermode = OUTSIDE, height=20, width =100, x = 300, y = 60)
texto = Label(ventana, text = "C1")
texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 100)
texto=Label(ventana,text='C2')
texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 140)
textores2 = Label(ventana, text = "v2")
textores2.place(bordermode = OUTSIDE, height = 20, width = 150, x = 50, y = 250)
else:
messagebox.showerror('Error','Fuera de Rango')
##operacion del boton calcular
def calcular():
global cas
variable1 = vari1.get()
variable2 = vari2.get()
variable3 = vari3.get()
if cas == 1:
v2=float(variable1)
v1= float(variable2)
c2= float(variable3)
##operacion
resultado = (c2*v2)/v1
rest.set(resultado)
elif cas == 2:
v2=float(variable1)
v1 = float(variable2)
c1 = float(variable3)
resultado = (c1*v1)/v2
rest.set(resultado)
elif cas == 3:
v2=float(variable1)
c1 = float(variable2)
c2 = float(variable3)
resultado =(c2*v2)/c1
rest.set(resultado)
elif cas == 4:
v1 = float(variable1)
c1 = float(variable2)
c2 = float(variable3)
resultado = (c1 *v1)/c2
rest.set(resultado)
else:
messagebox.showerror('Error','Selecciona una Variable')
def acerca():
messagebox.showinfo('acerca de','Desarrollado por Israel Nuñez')
ventana = Frame (height = 300, width = 600)
ventana.pack(padx =10, pady = 10)
variable1 = DoubleVar()
variable2 = DoubleVar()
variable3 = DoubleVar()
cas = 0
rest = StringVar()
#probando listbox
textolb = Label(ventana, text = "Seleccione Variable")
textolb.place(bordermode = OUTSIDE, height = 20, width = 150, x= 100, y= 20)
lb = Listbox(ventana)
lb.insert(1,"C1")
lb.insert(2,"C2")
lb.insert(3,"V1")
lb.insert(3,"V2")
lb.bind('<>',variables)
lb.place(bordermode = OUTSIDE, height = 100, width = 150, x = 100, y= 40)
#boton calcular
boton = Button(ventana, text = "calcular",command= calcular )
boton.place(bordermode = OUTSIDE, height = 30, width =80, x=350, y = 200)
#boton acercade
boton2 = Button(ventana, text ="acerca de...", command = acerca)
boton2.place (bordermode = OUTSIDE , height = 30, width = 80, x= 450, y= 200)
#texto de presentacion
texto=Label(ventana,text='Variable 1')
texto.place(bordermode = OUTSIDE, height=20, width =100, x = 300, y = 60)
texto = Label(ventana, text = "Variable 2")
texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 100)
texto = Label(ventana, text = "Variable 3")
texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 140)
#Entrada de Datos
vari1 = Entry(ventana, textvariable =variable1)
vari1.place(bordermode= OUTSIDE, height= 30, width = 100, x= 400, y= 100)
vari2 = Entry(ventana,textvariable=variable2)
vari2.place(bordermode= OUTSIDE, height= 30, width = 100, x= 400, y= 140)
vari3 = Entry(ventana, textvariable = variable3)
vari3.place(bordermode = OUTSIDE, height = 30, width = 100, x= 400, y= 60)
#para mostrar resultados
textores = Label(ventana, text = "Resultado")
textores.place(bordermode = OUTSIDE, height = 20, width = 150, x= 100, y= 200)
textores2 = Label(ventana, text = "Variable")
textores2.place(bordermode = OUTSIDE, height = 20, width = 150, x = 50, y = 250)
res = Label(ventana,textvariable = rest, fg = "blue",bg = "yellow")
res.place(bordermode = OUTSIDE, height = 20, width = 200, x = 200, y = 250)