किसी भी टिंकर एप्लिकेशन में बटन एक बहुत ही उपयोगी विजेट हैं। एंट्री विजेट में मान डालने वाले फ़ंक्शन को परिभाषित करके हम एंट्री विजेट में किसी भी बटन का मान प्राप्त कर सकते हैं। मान प्राप्त करने के लिए, हमें पहले एंट्री विजेट पर प्रदर्शित होने वाले विशिष्ट मान को जोड़ने के लिए कमांड वाले बटन को परिभाषित करना होगा।
एंट्री विजेट को अपडेट करने के लिए, हम delete(0, END) का उपयोग करके पिछले मान को हटा सकते हैं। विधि।
उदाहरण
# Import the required libraries
from tkinter import *
from tkinter import ttk
# Create an instance of tkinter frame or window
win=Tk()
# Set the size of the window
win.geometry("700x350")
def on_click(text):
entry.delete(0, END)
entry.insert(0,text)
# Add an Entry widget
entry=Entry(win, width= 25)
entry.pack()
# Add Buttons in the window
b1=ttk.Button(win, text= "A", command=lambda:on_click("A"))
b1.pack()
b2=ttk.Button(win, text= "B", command=lambda: on_click("B"))
b2.pack()
b3=ttk.Button(win, text= "C", command=lambda: on_click("C"))
b3.pack()
win.mainloop() आउटपुट
उपरोक्त कोड को चलाने से एक विंडो प्रदर्शित होगी जिसमें कई बटन होंगे। जब हम एक बटन पर क्लिक करते हैं, तो यह एंट्री फील्ड में अपना मान प्रदर्शित करेगा।