[TK] Calculadora by sokoleonardo
2 participantes
Página 1 de 1.
[TK] Calculadora by sokoleonardo
[Tienes que estar registrado y conectado para ver esa imagen]
- Código:
# Sencilla calculadora by sokoleonardo
from Tkinter import *
import sys
mi_script = sys.argv[0]
titulo = mi_script.split("\\")[-1]
mi_ventana = Tk()
mi_ventana.wm_title(titulo)
mi_ventana.wm_maxsize(width=198, height=190)
mi_ventana.wm_minsize(width=198, height=190)
mi_ventana.wm_iconbitmap(bitmap=mi_script)
def resultar(tipo,n1,n2):
resultado = Label(mi_ventana,text=" "*63)
resultado.place(x=12,y=140)
if len(n1) > 10 or len(n2) > 10:
resultado = Label(mi_ventana,text="\tCifra muy larda")
resultado.place(x=12,y=140)
else:
n1 = int(n1)
n2 = int(n2)
if tipo == "+": salida = n1 + n2
elif tipo == "-": salida = n1 - n2
elif tipo == "*": salida = n1 * n2
elif tipo == "/": salida = n1 / n2
else: salida = n1 * n2 / 100
resultadoFinal = str(n1)+" "+tipo+" "+str(n2)+" = "+str(salida)
resultado = Label(mi_ventana,text=resultadoFinal)
resultado.place(x=6,y=140)
del resultado
texN1 = Label(mi_ventana,text="N*1:",fg="violet")
texN1.place(x=1,y=13)
Num1 = Entry(mi_ventana,fg="red")
Num1.place(x=31,y=10,height=23,width=160)
texN2 = Label(mi_ventana,text="N*2:",fg="violet")
texN2.place(x=1,y=39)
Num2 = Entry(mi_ventana,fg="red")
Num2.place(x=31,y=39,height=23,width=160)
def Suma():
cifra1=Num1.get()
cifra2=Num2.get()
resultar("+",cifra1,cifra2)
def Resta():
cifra1=Num1.get()
cifra2=Num2.get()
resultar("-",cifra1,cifra2)
def Multiplicacion():
cifra1=Num1.get()
cifra2=Num2.get()
resultar("*",cifra1,cifra2)
def Division():
cifra1=Num1.get()
cifra2=Num2.get()
resultar("/",cifra1,cifra2)
def Porcentaje():
cifra1=Num1.get()
cifra2=Num2.get()
resultar("%",cifra1,cifra2)
def Borrar():
fin=len(Num1.get())
fin2=len(Num2.get())
Num1.delete(first=0, last=fin)
Num2.delete(first=0, last=fin2)
b="blue"
boton1 = Button(mi_ventana,text="C",height=2,width=3,fg="red",command=Borrar)
boton1.place(x=4,y=65)
boton2 = Button(mi_ventana,text="+",height=2,width=3,fg=b,command=Suma)
boton2.place(x=43,y=65)
boton3 = Button(mi_ventana,text="_",height=2,width=3,fg=b,anchor="n",command=Resta)
boton3.place(x=74,y=65)
boton4 = Button(mi_ventana,text="x",height=2,width=3,fg=b,command=Multiplicacion)
boton4.place(x=105,y=65)
boton5 = Button(mi_ventana,text="/",height=2,width=3,fg=b,command=Division)
boton5.place(x=136,y=65)
boton6 = Button(mi_ventana,text="%",height=2,width=3,fg=b,command=Porcentaje)
boton6.place(x=167,y=65)
titulo = Label(mi_ventana,text="Resultado:",fg="green")
titulo.place(x=12,y=110)
mi_ventana.mainloop()
# Fin
Sokoleonardo- Moderador de Seccion
- Mensajes : 52
Nivel : 138
Reputación : 4
Fecha de inscripción : 04/08/2011
Vive en : Argentina
Re: [TK] Calculadora by sokoleonardo
mmmmmm sencilla pero eficiente para las pcs de extremo bajo rendimiento xD
Temas similares
» [TK] Reproductor de .mp3 by sokoleonardo
» [Tk] PowerM (Reproduce mucha musica) By Sokoleonardo
» Crear menus profecionales en Tkinter. by Sokoleonardo
» [Tk] PowerM (Reproduce mucha musica) By Sokoleonardo
» Crear menus profecionales en Tkinter. by Sokoleonardo
Página 1 de 1.
Permisos de este foro:
No puedes responder a temas en este foro.
|
|
Vie Sep 05, 2014 6:15 pm por JAVIER_77
» Hacker nostale
Vie Jul 20, 2012 5:02 pm por Sweet_Boy
» Chrome OS 20.x pasa al canal estable
Vie Jul 13, 2012 11:15 pm por [D]ement<<<
» Disponible openSUSE 12.2 RC 1
Vie Jul 13, 2012 12:44 am por [D]ement<<<
» NitroShare, comparte archivos y carpetas entre Linux y Windows
Vie Jul 13, 2012 12:26 am por [D]ement<<<
» Linux Mint 13 KDE Release Candidate, disponible
Vie Jul 13, 2012 12:18 am por [D]ement<<<
» LibreOffice 3.5.5, más estabilidad
Vie Jul 13, 2012 12:06 am por [D]ement<<<
» File History, un Time Machine para Windows 8
Miér Jul 11, 2012 9:50 pm por [D]ement<<<
» Como habilitar el logueo automático en Windows
Miér Jul 11, 2012 9:44 pm por [D]ement<<<
» Acronis True Image 2012
Mar Jul 10, 2012 12:15 am por [D]ement<<<
» Virus Informaticos
Mar Mayo 08, 2012 7:10 am por Sokoleonardo