- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- 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 set the text/value/content of an 'Entry' widget using a button in Tkinter?
Tkinter Entry widget is used to display a single line text. Using tkinter Entry widget, we can set its value or content by triggering a button. It has mainly two types of operation: insert and delete.
Using the Tkinter Button widget, we will set the content of the Entry widget.
Example
#Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Define a function to change the value def change_text(txt): text.delete(0,END) text.insert(0,txt) #Set the geometry of frame win.geometry("600x250") #Create an Entry Widget text= Entry(win) text.pack() #Create a button to change/set the content btn= Button(win,text="Set", command=lambda:change_text("My New Text")) btn.pack(pady=20) win.mainloop()
Output
Running the code will display a window containing a button that will set the value or text of the entry widget.
Now click on the “Set” button to set a new value for Entry Widget.
Advertisements