콜백을 사용하여 입력 상자에서 버튼의 값을 가져올 수있는 몇 가지 코드를 제공합니다. 질문은 어떻게 두 개의 연결된 값을 입력 상자에 콜백 할 수 있는가입니다. 사용자가 1을 누른 다음 7을 누르면 값 17이 표시됩니다.Tkinter의 버튼에서 입력 상자의 다중 항목
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()
당신은 계산 방법을 묻지 않았습니다. 올바르게 입력하는 방법은 ... 오. – jwillis0720