python-by-example-150-chall.../challenges124_132/challenge-126_.py

46 lines
1.0 KiB
Python
Raw Normal View History

2021-12-08 19:08:24 +08: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("Adding Together")
window.geometry("450x100")
enter_lbl=Label(text="Enter a number: ")
enter_lbl.place(x=50, y=20, width=100, height=25)
enter_txt=Entry(text=0)
enter_txt.place(x=150, y=20, width=100, height=25)
enter_txt["justify"]="center"
enter_txt.focus()
add_btn=Button(text="Add", command=add_on)
add_btn.place(x=300, y=20, width=50, height=25)
output_lbl=Label(text="Answer= ")
output_lbl.place(x=50, y=50, width=100, height=25)
output_txt=Message(text=0)
output_txt.place(x=150, y=50, width=100, height=25)
output_txt["bg"]="white"
output_txt["relief"]="sunken"
clear_btn=Button(text="Clear", command=reset)
clear_btn.place(x=300, y=50, width=50, height=25)
window.mainloop()