python_by_example/tkgui/sols_124-132/sol_03.py

47 lines
1.0 KiB
Python
Raw Normal View History

2023-11-17 13:26:09 -03:00
from tkinter import *
def add_on():
num = enter_txt.get()
num = int(num)
answer = output_txt["text"]
answer = int(answer)
total = num + answer
output_txt["text"] = total
def reset():
total = 0
output_txt["text"] = 0
enter_txt.delete(0, 'end')
enter_txt.focus()
total = 0
num = 0
window = Tk()
window.title("Agregando números")
window.geometry("450x100")
enter_lbl = Label(text="Ingresa un número:")
enter_lbl.place(x=50, y=20, width=120, height=25)
enter_txt = Entry()
enter_txt.place(x=175, y=20, width=120, height=25)
enter_txt["justify"] = "center"
enter_txt.focus()
add_btn = Button(text="Agregar", command=add_on)
add_btn.place(x=300, y=20, width=55, height=25)
output_lbl = Label(text="TOTAL = ")
output_lbl.place(x=110, y=50, width=70, height=25)
output_txt = Message(text=0)
output_txt.place(x=175, y=50, width=120, height=25)
output_txt["bg"] = "white"
output_txt["relief"] = "sunken"
clear_btn = Button(text="Borrar", command=reset)
clear_btn.place(x=300, y=50, width=55, height=25)
window.mainloop()