Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- """ Programa que implementa una calculadora gráfica rudimentaria"""
- import tkinter as tk
- ######### funciones ################
- def suma():
- suma = float(caja1.get()) + float(caja2.get())
- ingresa_texto.set(str(suma))
- def resta():
- resta = float(caja1.get()) - float(caja2.get())
- ingresa_texto.set(str(resta))
- def producto():
- producto = float(caja1.get()) * float(caja2.get())
- ingresa_texto.set(str(producto))
- def cociente():
- cociente = float(caja1.get()) / float(caja2.get())
- ingresa_texto.set(str(cociente))
- ######### entorno gráfico #############
- ventana = tk.Tk()
- ventana.config(width=400, height=300, bg="khaki")
- ventana.title("Calculadora")
- ingresa_texto = tk.StringVar() # el valor de esta variable se muestra en la pantalla
- ingresa_texto.set("0")
- ## campo primer termino ####
- caja1 = tk.Entry()
- caja1.place(x=20, y=20, width=50, height=25)
- etiqueta = tk.Label(text="Primer valor", bg="khaki")
- etiqueta.place(x=20, y=50)
- ## campo segundo termino ####
- caja2 = tk.Entry()
- caja2.place(x=120, y=20, width=50, height=25)
- etiqueta = tk.Label(text="Segundo valor", bg="khaki")
- etiqueta.place(x=120, y=50)
- ## campo pantalla ####
- pantalla = tk.Entry(
- font=['arial',12,'bold'],
- textvariable = ingresa_texto,
- justify = "right",
- state = tk.DISABLED # bloquea el ingreso de datos
- )
- pantalla.place(x=220, y=20, width=150, height=25)
- etiqueta = tk.Label(text="Total", bg="khaki")
- etiqueta.place(x=220, y=50)
- ###### botones ######################################
- ### suma #######
- boton = tk.Button(text="SUMA", bg="lightblue", command=suma)
- boton.place(x=10, y=100, width=100, height=30)
- ### resta #######
- boton = tk.Button(text="RESTA", bg="lightblue", command=resta)
- boton.place(x=130, y=100, width=100, height=30)
- ### producto #######
- boton = tk.Button(text="PRODUCTO", bg="lightblue", command=producto)
- boton.place(x=10, y=150, width=100, height=30)
- ### cociente #######
- boton = tk.Button(text="COCIENTE", bg="lightblue", command=cociente)
- boton.place(x=130, y=150, width=100, height=30)
- ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement