- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 insert text at the beginning of the text box in Tkinter?
There are two types of Text editors that Tkinter supports -- the Entry widget and the Text widget. Tkinter text widgets are used to create the text editor where we can edit, add or delete the text whenever we need. We can create a text widget using the Text(parent) constructor. In order to insert a default text for the text widget, we can use the insert(INSERT, "text_to_insert") or insert("1.0", "text_to_insert") method after the text widget declaration.
Example
In this example, we will insert the text at the beginning of the text box.
#Import the required Libraries from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry of tkinter frame win.geometry("750x250") #Create a Text Box text= Text(win, width= 50, height= 30, background= "gray71",foreground="#fff",font= ('Sans Serif', 13, 'italic bold')) #Insert the text at the begining text.insert(INSERT, "Write Something About Yourself") text.pack(expand= 1, fill= BOTH) win.mainloop()
Output
Run the above code to display the text box in the window.
In the given output, the default text is initially set to the beginning in the text box.
- Related Articles
- How to insert a text at the beginning of a file in Linux?
- How to place the text at the center of an Entry box in Tkinter?
- How to set justification on Tkinter Text box?
- Specify the dimensions of a Tkinter text box in pixels
- How to Delete Tkinter Text Box's Contents?
- How to Add Text at the Beginning or End of All Cells in Excel?
- How to insert a temporary text in a tkinter Entry widget?
- How to get the current length of the Text in a Tkinter Text widget?
- How to word-wrap text in Tkinter Text?
- How to display LaTex in real time in a text box in Tkinter?
- How to input text in the text box without calling the sendKeys() using Selenium?
- How to highlight text in a tkinter Text widget?
- How to get the Tkinter Label text?
- How do I center the text in a Tkinter Text widget?
- How to take input in a text widget and display the text in tkinter?

Advertisements