Advertisement
teslariu

Untitled

Jan 2nd, 2021
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # binding --> adaptación de una libreria escrita en otro lenguaje
  5. # TCL lenguaje microcontroladores + tk librería para implementar aplicaciones gráficos
  6. # TCL/Tk --> binding para python obtengo tkinter
  7.  
  8.  
  9. import tkinter as tk
  10.  
  11. def suma():
  12.     a = float(caja1.get())
  13.     b = float(caja2.get())
  14.     print(f"La suma es {a+b}")
  15.     resultado.set(str(a+b))
  16.  
  17.  
  18. ###### programa principal #############################
  19.  
  20. ventana = tk.Tk()
  21. ventana.config(width=400, height=300, bg="light steel blue")
  22. ventana.title("Mi primera aplicación")
  23.  
  24. resultado = tk.StringVar()
  25. resultado.set("0")
  26.  
  27. boton = tk.Button(text="SUMAR", command=suma)
  28. boton.place(x=70, y=150, width=100, height=30)
  29.  
  30. # Primer sumando
  31. caja1 = tk.Entry()
  32. caja1.place(x=40, y=30, width=40, height=25)
  33.  
  34. etiqueta = tk.Label(text="Primer sumando" ,bg="light steel blue")
  35. etiqueta.place(x=15, y=60)
  36.  
  37. # Segundo sumando
  38. caja2 = tk.Entry()
  39. caja2.place(x=200, y=30, width=40, height=25)
  40.  
  41. etiqueta = tk.Label(text="Segundo sumando",bg="light steel blue")
  42. etiqueta.place(x=185, y=60)
  43.  
  44. # Muestra el resultado de la suma en la interfaz gráfica
  45. pantalla = tk.Entry(
  46.                 font=['arial',14, 'italic'],
  47.                 width=100,
  48.                 textvariable = resultado,
  49.                 justify ="center",
  50.                 bd=4,
  51.                 state=tk.DISABLED
  52.                 )
  53.  
  54. pantalla.place(
  55.             x=100,
  56.             y=100,
  57.             width=100,
  58.             height=25
  59.             )
  60.  
  61. etiqueta = tk.Label(text="SUMA",bg="light steel blue")
  62. etiqueta.place(x=50, y=100)
  63.  
  64.  
  65. ventana.mainloop()
  66.  
  67.  
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement