- 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 can I insert a string in an Entry widget that is in the "readonly" state using Tkinter?
Tkinter Entry widget is used to insert single-line text input. We can use the Entry widget to create forms where single-line input is the prime requirement.
Sometimes, we need to insert a predefined text inside the Entry Widget. In such cases, we can use insert(INSERT,<Your Text>) method. These are generally called as Placeholders for the Entry widget.
Let us suppose that we want to change the state of our text as read-only. Here, we can use state= ‘readonly’ property while configuring the Entry widget.
Example
#Import the required Libraries from tkinter import * from tkinter import ttk #Create an instance of tkinter frame win = Tk() #Set the geometry of tkinter frame win.geometry("750x270") #Create an Entry Widget entry= ttk.Entry(win, width= 40) entry.insert(0, 'www.tutorialspoint.com') #Set the state of Entry widget ReadOnly entry.configure(state= "readonly") entry.pack(ipadx= 20,ipady=10) win.mainloop()
Output
Running the above code will display a window that will have an Entry widget containing a single text which cannot be modified.
Advertisements