Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- !/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # calculadora grafica que suma dos números
- import tkinter as tk
- def sumar():
- suma = float(primer_sumando.get()) + float(segundo_sumando.get())
- suma_total.set(str(suma))
- ventana = tk.Tk()
- ventana.config(width=600, height=300, bg = "Light Steel Blue")
- ventana.title("Sumador")
- suma_total = tk.StringVar()
- suma_total.set("0")
- # título de la aplicación
- etiqueta = tk.Label(text="Sumador de dos números", font = ('arial',20,'bold'))
- etiqueta.place(x=80, y=10)
- ################## campos: primer sumando, segundo sumando y total
- # primer sumando
- primer_sumando = tk.Entry(font = ('arial',20,'italic'), justify = "right")
- primer_sumando.place(x=50, y=80, width=100, height=35)
- etiqueta = tk.Label(text="Primer sumando", bg = "Light Steel Blue")
- etiqueta.place(x=50, y=120)
- # segundo sumando
- segundo_sumando = tk.Entry(font = ('arial',20,'italic'), justify = "right")
- segundo_sumando.place(x=450, y=80, width=100, height=35)
- etiqueta = tk.Label(text="Segundo sumando", bg = "Light Steel Blue")
- etiqueta.place(x=450, y=120)
- # total
- total = tk.Entry(
- font = ('arial',20,'italic'),
- textvariable=suma_total,
- state = tk.DISABLED,
- justify = "center"
- )
- total.place(x=250, y=150, width=100, height=35)
- etiqueta = tk.Label(text="Total", bg = "Light Steel Blue")
- etiqueta.place(x=280, y=190)
- # state = tk.DISABLED impide escribir dentro de una caja de texto
- # textvariable=suma muestra el contenido de la variable suma en la caja de texto
- ######### botón de suma ##############
- boton = tk.Button(text="SUMAR", command = sumar)
- boton.place(x=250, y=230, width=100, height=30)
- ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement