Advertisement
teslariu

sumador

Apr 24th, 2021
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import tkinter as tk
  5. from tkinter import ttk
  6. ventana = tk.Tk()
  7. ventana.title("sumador")
  8. ventana.config(width=400, height=300)
  9.  
  10. def sumar():
  11.     global resultado
  12.     primer_sumando = float(a.get())
  13.     segundo_sumando = float(b.get())
  14.     total = primer_sumando + segundo_sumando
  15.     resultado.set(str(total))
  16.  
  17. ###########  comienzo programa principal ##############
  18.  
  19. resultado = tk.StringVar()
  20. resultado.set("0")
  21.  
  22. ##### campo primer sumando a ################
  23. a = ttk.Entry(justify = "right",)
  24. a.place(x=10, y=10, width=200, height=25)
  25. etiqueta = ttk.Label(text="Primer sumando")
  26. etiqueta.place(x=220, y=10)
  27.  
  28. ##### campo segundo sumando b ################
  29. b = ttk.Entry(justify = "right",)
  30. b.place(x=10, y=50, width=200, height=25)
  31. etiqueta = ttk.Label(text="Segundo sumando")
  32. etiqueta.place(x=220, y=50)
  33.  
  34. ##### campo pantalla de resultados ################
  35. pantalla = ttk.Entry(textvariable=resultado, justify = "right", state = tk.DISABLED)
  36. pantalla.place(x=10, y=90, width=200, height=25)
  37. etiqueta = ttk.Label(text="Total de la suma")
  38. etiqueta.place(x=220, y=90)
  39.  
  40. # boton suma
  41. boton = ttk.Button(text="Sumar", command=sumar)
  42. boton.place(x=50, y=130)
  43.  
  44.  
  45. ventana.mainloop()
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement