Advertisement
teslariu

sumador

Apr 15th, 2021
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. !/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # calculadora grafica que suma dos números
  5.  
  6. import tkinter as tk
  7.  
  8. def sumar():
  9.     suma = float(primer_sumando.get()) + float(segundo_sumando.get())
  10.     suma_total.set(str(suma))
  11.    
  12.  
  13. ventana = tk.Tk()
  14. ventana.config(width=600, height=300, bg = "Light Steel Blue")
  15. ventana.title("Sumador")
  16.  
  17. suma_total = tk.StringVar()
  18. suma_total.set("0")
  19.    
  20.  
  21. # título de la aplicación
  22. etiqueta = tk.Label(text="Sumador de dos números", font = ('arial',20,'bold'))
  23. etiqueta.place(x=80, y=10)
  24.  
  25. ################## campos: primer sumando, segundo sumando y total
  26.  
  27. # primer sumando
  28. primer_sumando = tk.Entry(font = ('arial',20,'italic'), justify = "right")
  29. primer_sumando.place(x=50, y=80, width=100, height=35)
  30. etiqueta = tk.Label(text="Primer sumando", bg = "Light Steel Blue")
  31. etiqueta.place(x=50, y=120)
  32.  
  33. # segundo sumando
  34. segundo_sumando = tk.Entry(font = ('arial',20,'italic'), justify = "right")
  35. segundo_sumando.place(x=450, y=80, width=100, height=35)
  36. etiqueta = tk.Label(text="Segundo sumando", bg = "Light Steel Blue")
  37. etiqueta.place(x=450, y=120)
  38.  
  39. # total
  40. total = tk.Entry(
  41.             font = ('arial',20,'italic'),
  42.             textvariable=suma_total,
  43.             state = tk.DISABLED,
  44.             justify = "center"
  45.             )
  46.  
  47.  
  48. total.place(x=250, y=150, width=100, height=35)
  49. etiqueta = tk.Label(text="Total", bg = "Light Steel Blue")
  50. etiqueta.place(x=280, y=190)
  51. # state = tk.DISABLED impide escribir dentro de una caja de texto
  52. # textvariable=suma muestra el contenido de la variable suma en la caja de texto
  53.  
  54.  
  55.  
  56. #########  botón de suma ##############
  57. boton = tk.Button(text="SUMAR", command = sumar)
  58. boton.place(x=250, y=230, width=100, height=30)
  59.  
  60.  
  61. ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement