Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # binding --> adaptación de una libreria escrita en otro lenguaje
- # TCL lenguaje microcontroladores + tk librería para implementar aplicaciones gráficos
- # TCL/Tk --> binding para python obtengo tkinter
- import tkinter as tk
- def suma():
- a = float(caja1.get())
- b = float(caja2.get())
- print(f"La suma es {a+b}")
- resultado.set(str(a+b))
- ###### programa principal #############################
- ventana = tk.Tk()
- ventana.config(width=400, height=300, bg="light steel blue")
- ventana.title("Mi primera aplicación")
- resultado = tk.StringVar()
- resultado.set("0")
- boton = tk.Button(text="SUMAR", command=suma)
- boton.place(x=70, y=150, width=100, height=30)
- # Primer sumando
- caja1 = tk.Entry()
- caja1.place(x=40, y=30, width=40, height=25)
- etiqueta = tk.Label(text="Primer sumando" ,bg="light steel blue")
- etiqueta.place(x=15, y=60)
- # Segundo sumando
- caja2 = tk.Entry()
- caja2.place(x=200, y=30, width=40, height=25)
- etiqueta = tk.Label(text="Segundo sumando",bg="light steel blue")
- etiqueta.place(x=185, y=60)
- # Muestra el resultado de la suma en la interfaz gráfica
- pantalla = tk.Entry(
- font=['arial',14, 'italic'],
- width=100,
- textvariable = resultado,
- justify ="center",
- bd=4,
- state=tk.DISABLED
- )
- pantalla.place(
- x=100,
- y=100,
- width=100,
- height=25
- )
- etiqueta = tk.Label(text="SUMA",bg="light steel blue")
- etiqueta.place(x=50, y=100)
- ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement