कई अनुप्रयोगों में बटन बहुत उपयोगी होते हैं जहां उपयोगकर्ता सहभागिता की आवश्यकता होती है। आइए मान लें कि हम जानना चाहते हैं कि किसी दिए गए एप्लिकेशन में कौन सा बटन दबाया गया है। बटन के बारे में जानकारी प्राप्त करने के लिए, हम बटन कॉन्फ़िगरेशन में कॉलबैक फ़ंक्शन का उपयोग कर सकते हैं। कॉलबैक फ़ंक्शन में, हम प्रिंट (परीक्षण) . का उपयोग करेंगे क्लिक किए गए बटन को प्रिंट करने के लिए कार्य करता है।
उदाहरण
#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() आउटपुट
उपरोक्त कोड को चलाने पर दो बटन वाली एक विंडो प्रदर्शित होगी।

यदि आप "बटन-1" पर क्लिक करते हैं, तो यह निम्नलिखित को कंसोल पर प्रिंट करेगा।
Button-1 Clicked