- 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 add placeholder to an Entry in tkinter?
Tkinter provides features to add widgets such as button, text, entry, dialogue and other attributes that help to develop an application. However, tkinter doesn't include a placeholder in the entry widget. Placeholders are the dummy text that appears in the entry widget to inform the user about it.
In this article, we will add a placeholder in the entry widget using the insert(default value, text) function that takes a default value such as 0 along with the placeholder text.
Example
#Import tkinter library from tkinter import* #Create an instance of frame win= Tk() #Set geometry win.geometry("700x400") #Create a text Label Label(win, text="Notepad", font=('Poppins bold', 25)).pack(pady=20) text= StringVar() #Create an entry widget test= Entry(win, textvariable=text) test.pack(fill='x', expand=True, padx= 45, pady=45) test.focus() #Add a placeholder in the entry Widget test.insert(0, "Enter any Text") win.mainloop()
Output
Running the above code will create an Entry Widget with some placeholder in it.
Advertisements