버튼은 사용자 상호 작용이 필요한 많은 응용 프로그램에서 매우 유용합니다. 주어진 애플리케이션에서 어떤 버튼이 눌렸는지 알고 싶다고 가정해 봅시다. Button에 대한 정보를 얻기 위해 Button 구성에서 콜백 함수를 사용할 수 있습니다. 콜백 함수에서 print(test)를 사용합니다. 클릭한 버튼을 출력하는 기능입니다.
예시
#Import the required libraries
from tkinter import *
from tkinter import ttk
#Create an instance of Tkinter Frame
win = Tk()
#Set the geometry
win.geometry("700x250")
# Define function to get the information about the Button
def get_button(t):
print(t)
#Create Button Object
b1= ttk.Button(win, text= "Button-1", command= lambda t= "Button-1 Clicked": get_button(t))
b1.place(relx= .46, rely= .5, anchor= CENTER)
b2= ttk.Button(win, text= "Button-2", command= lambda t= "Button-2 Clicked": get_button(t))
b2.place(relx= .58, rely= .5, anchor= CENTER)
win.mainloop() 출력
위의 코드를 실행하면 두 개의 버튼이 있는 창이 표시됩니다.

"Button-1"을 클릭하면 콘솔에 다음과 같이 출력됩니다.
Button-1 Clicked