Tkinter Text Insert text
insert() can insert a string into the specified index position, it is used in the following format.
insert(index, string)
If END or INSERT is used for the index position, it means that the string will be inserted at the end of the file.
Example#1
Inserts a string into the end position of the Text text area.
from tkinter import *
root = Tk()
root.title("apidemos.com")
text = Text(root,height=3,width=30)
text.pack()
text.insert(END,"Welcome to apidemos.com\nWelcome to apidemos.com\n")
text.insert(INSERT,"apidemos.com")
root.mainloop()
Output:
Example#2
Insert a string of length 30 and observe the execution result.
from tkinter import *
root = Tk()
root.title("apidemos.com")
text = Text(root,height=3,width=30)
text.pack()
myString = \
"""apidemos.com provides tutorials on the basics of programming, introducing the basics of various programming languages such as HTML, CSS, Javascript, Python, Java, Ruby, C, PHP , MySQL and more. The site also provides a large number of online examples, through the examples, you can better learn programming..."""
text.insert(END,myString)
root.mainloop()
Output:
To improve this situation, you can add the Scrollbar to this Text control and use the Scrollbar to view the content.