I have provided some code that uses callbacks to allow an Entry box to take a value from a button. The question is, how can I callback two concatenated values into the entry box. If the user clicks 1 and then 7, the value of 17 is shown.
from tkinter import *
win = Tk()
win.geometry("210x125")
def set_text(text):
e.insert(0,text)
return
e = Entry(win,width=35)
e.grid(columnspan=4)
seven_button = Button(win,width=6,text="7",command=lambda:set_text("7")).grid(row=1, column=0)
eight_button = Button(win,width=6,text="8",command=lambda:set_text("8")).grid(row=1, column=1)
nine_button = Button(win,width=6,text="9",command=lambda:set_text("9")).grid(row=1, column=2)
div_button = Button(win,width=6,text="÷",command=lambda:set_text("÷")).grid(row=1, column=3)
four_button = Button(win,width=6,text="4",command=lambda:set_text("4")).grid(row=2, column=0)
five_button = Button(win,width=6,text="5",command=lambda:set_text("5")).grid(row=2, column=1)
six_button = Button(win,width=6,text="6",command=lambda:set_text("6")).grid(row=2, column=2)
multiply_button = Button(win,width=6,text="x",command=lambda:set_text("x")).grid(row=2, column=3)
one_button = Button(win,width=6,text="1",command=lambda:set_text("1")).grid(row=3, column=0)
two_button = Button(win,width=6,text="2",command=lambda:set_text("2")).grid(row=3, column=1)
three_button = Button(win,width=6,text="3",command=lambda:set_text("3")).grid(row=3, column=2)
minus_button = Button(win,width=6,text="-",command=lambda:set_text("-")).grid(row=3, column=3)
zero_button = Button(win,width=14,text="0",command=lambda:set_text("0")).grid(columnspan=2)
point_button = Button(win,width=6,text=".",command=lambda:set_text(".")).grid(row=4, column=2)
plus_button = Button(win,width=6,text="+",command=lambda:set_text("+")).grid(row=4, column=3)
win.mainloop()
if you want full functionality, might i suggest adding an equals button that will compute everything in the entry widget?
Note i changed the division sign and some of the logic of the entry so it would enter the left to right.