Tkinter

Text Tkinter | Python 3

In this tutorial, we are going to see how to use Text widget in Tkinter. Text widgets provide advanced features that allow you to edit multiline text and format the way it should be displayed, such as changing its color and font.

You can also use elegant structures like tabs to locate specific sections of text and apply changes to those areas. Also, you can embed windows and images in the text as this widget was designed to handle both plain and formatted text.
 


 
 

Syntax:

Here is the syntax to create this widget:

text = Text ( master, option = value, ... )

 

Parameters:
  • master : This represents the parent window.
  • options : Options can be used as comma separated key-value pairs. See the following example:

 

 

Example:
from tkinter import *

gui = Tk()
text = Text(gui, height=10, width=50)
text.insert(INSERT, "Hello.....")
text.insert(END, "Welcome to StackHowTo")
text.pack()

text.tag_add("hello", "1.0", "1.5")
text.tag_add("stackhowto", "1.21", "1.32")
text.tag_config("hello", background="red", foreground="blue")
text.tag_config("stackhowto", background="black", foreground="white")
gui.mainloop()

Output:


 
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *