Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- """
- Instalación de pyinstaller:
- python -m pip install pyinstaller
- # Dentro de la carpeta donde tengo el archivo desde CMD, ejecutar
- pyinstaller --onefile --noconsole calcu.py
- """
- import tkinter as tk
- from math import sqrt, factorial , pi
- def clic(tecla):
- global cuenta_consola
- cuenta_consola = cuenta_consola + tecla
- cuenta.set(cuenta_consola)
- def borrar_pantalla():
- global cuenta_consola
- cuenta_consola = ""
- cuenta.set("0")
- def hacer_cuenta():
- global cuenta_consola
- try:
- total = str(eval(cuenta_consola))
- cuenta.set(total)
- except Exception:
- borrar_pantalla()
- cuenta.set("ERROR")
- def borrar_caracter():
- global cuenta_consola
- cuenta_consola = cuenta_consola[:-1]
- cuenta.set(cuenta_consola)
- calculadora = tk.Tk()
- calculadora.title("Calculadora ACME")
- calculadora.config(width=390, height=600, bg="Light Steel Blue")
- calculadora.resizable(0,0)
- # calculadora.iconbitmap("icono.ico")
- # variable para mostrar la cuenta en la pantalla
- cuenta = tk.StringVar()
- # variable para hacer la cuenta en la consola
- cuenta_consola = ""
- borrar_pantalla()
- # Creo la pantalla
- pantalla = tk.Entry(
- font = ('arial', 20, 'bold'),
- width = 20,
- bd = 15,
- bg = 'powder blue',
- justify = 'right',
- state = tk.DISABLED,
- textvariable = cuenta
- )
- pantalla.place(x=25, y=50)
- # defino las dimensiones de las teclas
- ancho = 10
- alto = 2
- ######### Teclas ########################
- b = tk.Button(text="DEL", width=ancho, height=alto, bg="medium aquamarine", command=borrar_caracter)
- b.place(x=287, y=140)
- ### Primera fila: 1 2 3 +
- b = tk.Button(text="1", width=ancho, height=alto, command=lambda:clic("1"))
- b.place(x=17, y=200)
- b = tk.Button(text="2", width=ancho, height=alto, command=lambda:clic("2"))
- b.place(x=107, y=200)
- b = tk.Button(text="3", width=ancho, height=alto, command=lambda:clic("3"))
- b.place(x=197, y=200)
- b = tk.Button(text="+", width=ancho, height=alto, bg="SteelBlue", command=lambda:clic("+"))
- b.place(x=287, y=200)
- ### Segunda fila 4 5 6 -
- b = tk.Button(text="4", width=ancho, height=alto, command=lambda:clic("4"))
- b.place(x=17, y=260)
- b = tk.Button(text="5", width=ancho, height=alto, command=lambda:clic("5"))
- b.place(x=107, y=260)
- b = tk.Button(text="6", width=ancho, height=alto, command=lambda:clic("6"))
- b.place(x=197, y=260)
- b = tk.Button(text="-", width=ancho, height=alto, bg="SteelBlue", command=lambda:clic("-"))
- b.place(x=287, y=260)
- ### Tercera fila: 7 8 9 x
- b = tk.Button(text="7", width=ancho, height=alto, command=lambda:clic("7"))
- b.place(x=17, y=320)
- b = tk.Button(text="8", width=ancho, height=alto, command=lambda:clic("8"))
- b.place(x=107, y=320)
- b = tk.Button(text="9", width=ancho, height=alto, command=lambda:clic("9"))
- b.place(x=197, y=320)
- b = tk.Button(text="x", width=ancho, height=alto, bg="SteelBlue", command=lambda:clic("*"))
- b.place(x=287, y=320)
- ### Cuarta fila: ( 0 ) /
- b = tk.Button(text="(", width=ancho, height=alto, bg="Sky Blue", command=lambda:clic("("))
- b.place(x=17, y=380)
- b = tk.Button(text="0", width=ancho, height=alto, command=lambda:clic("0"))
- b.place(x=107, y=380)
- b = tk.Button(text=")", width=ancho, height=alto, bg="Sky Blue", command=lambda:clic(")"))
- b.place(x=197, y=380)
- b = tk.Button(text="/", width=ancho, height=alto, bg="SteelBlue", command=lambda:clic("/"))
- b.place(x=287, y=380)
- ### Quinta fila: Raiz Coma decimal potencia resto
- b = tk.Button(text="\u221A", width=ancho, height=alto, bg="Sky Blue", command=lambda:clic("sqrt("))
- b.place(x=17, y=440)
- b = tk.Button(text=".", width=ancho, height=alto, bg="SteelBlue", command=lambda:clic("."))
- b.place(x=107, y=440)
- b = tk.Button(text="pow", width=ancho, height=alto, bg="Sky Blue", command=lambda:clic("**"))
- b.place(x=197, y=440)
- b = tk.Button(text="%", width=ancho, height=alto, bg="Sky Blue", command=lambda:clic("%"))
- b.place(x=287, y=440)
- ### Sexta fila: Clear Factorial PI =
- b = tk.Button(text="CL", width=ancho, height=alto, bg="medium aquamarine", command=borrar_pantalla)
- b.place(x=17, y=500)
- b = tk.Button(text="!", width=ancho, height=alto, bg="Sky Blue", command=lambda:clic("factorial("))
- b.place(x=107, y=500)
- b = tk.Button(text="\u03C0", width=ancho, height=alto, bg="Sky Blue", command=lambda:clic(str(pi)))
- b.place(x=197, y=500)
- b = tk.Button(text="=", width=ancho, height=alto, bg="medium aquamarine", command=hacer_cuenta)
- b.place(x=287, y=500)
- calculadora.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement