- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the value of a button in the Entry widget using Tkinter?
Buttons are a very useful widget in any Tkinter application. We can get the value of any button in the Entry widget by defining the function which inserts the value in the Entry widget. To get the value, we have to first define buttons having command for adding the specific value to be displayed on the Entry widget.
To update the Entry widget, we can delete the previous value using delete(0, END) method.
# 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()
Running the above code will display a window that contains a number of buttons in it. When we click a button, it will display its value in the Entry field.
- Related Articles
- How to get the value of an Entry widget in Tkinter?
- How to set the text/value/content of an 'Entry' widget using a button in Tkinter?
- How to clear the Entry widget after a button is pressed in Tkinter?
- Get contents of a Tkinter Entry widget
- Get the text of a button widget in Tkinter
- How to change the Entry Widget Value with a Scale in Tkinter?
- How to use the Entry widget in Tkinter?
- How to make a Button using the Tkinter Canvas widget?
- How to connect a variable to the Tkinter Entry widget?
- How to set the width of a Tkinter Entry widget in pixels?
- How to set the font size of Entry widget in Tkinter?
- Return the input of the Entry widget in Tkinter
- Setting the focus to a specific Tkinter entry widget
- How to disable an Entry widget in Tkinter?
- How to update a Button widget in Tkinter?