## teoremas para triangulos #pitagoras9 from tkinter import* from tkinter import messagebox import math def hola(e): global cas var = lb.curselection() var1 = tuple(('0',)) var2 = tuple(('1',)) var3 = tuple (('2')) if var == var1: ##calculando cateto opuesto cas = 1 texto = Label(ventana, text = "Hipotenusa") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 100) texto = Label(ventana, text = "C. Adyacente") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 140) textores2 = Label(ventana, text = "C. Opuesto") textores2.place(bordermode = OUTSIDE, height = 20, width = 150, x = 50, y = 250) elif var == var2: ##calculando cateto Adyacente cas = 2 texto = Label(ventana, text = "Hipotenusa") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 100) texto = Label(ventana, text = "C. Opuesto") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 140) textores2 = Label(ventana, text = "C. Adyacente") textores2.place(bordermode = OUTSIDE, height = 20, width = 150, x = 50, y = 250) elif var == var3: cas = 3 ##calculando hipotenusa texto = Label(ventana, text = "C. Opuesto") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 100) texto = Label(ventana, text = "C. Adyacente") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 140) textores2 = Label(ventana, text = "Hipotenusa") textores2.place(bordermode = OUTSIDE, height = 20, width = 150, x = 50, y = 250) else: print ('Fuera de Rango') ##operacion del boton calcular def calcular(): global cas variable1 = vari1.get() variable2 = vari2.get() if cas == 1: h=float(variable1) ca = float(variable2) ##operacion resultado = math.sqrt((h*h) - (ca*ca)) rest.set(resultado) elif cas == 2: h=float(variable1) co = float(variable2) resultado = math.sqrt((h*h) - (co*co)) rest.set(resultado) elif cas == 3: co=float(variable1) ca = float(variable2) resultado = math.sqrt((co*co) + (ca*ca)) rest.set(resultado) else: messagebox.showerror('Error','Selecciona una Variable') ventana = Frame (height = 300, width = 600) ventana.pack(padx =10, pady = 10) variable1 = DoubleVar() variable2 = 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,"Cateto Opuesto") lb.insert(2,"Cateto Abyacente") lb.insert(3,"Hipotenusa") lb.bind('<>' ,hola) lb.place(bordermode = OUTSIDE, height = 70, 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) #texto de presentacion texto = Label(ventana, text = "Variable 1") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 100) texto = Label(ventana, text = "Variable 2") 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) #para mostrar resustados 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)
videotutoriales de matlab, octave, numpy, python, POA, algoritmia, simulacion de procesos en ingenieria quimica, y algo de ingenieria quimica
miércoles, 24 de julio de 2013
Manejo de Listbox en Python 3.x. Usando Tkinter
Como ven es una pequeña aplicacion desarrollada en Python usando Tkinter en especial me enfoco en el uso de los Listbox, como veran es la aplicacion de todos los posibles casos del teorema de pitagoras, la funcion que controla el Listbox tiene por nombre hola, para que la identifiquen.
No hay comentarios:
Publicar un comentario