Tkinter Widget-Text

This widget is used to add the text in our Application and we can change its font, color etc.
Syntax-
w = Text (main, option)
Parameter-
Main- parent Window.
Option- attribute of text widget.
Example-
  1. from tkinter import *  
  2. def onclick():  
  3.        pass  
  4. main = Tk()  
  5. text = Text(main)  
  6. text.insert(INSERT, "c# corner-")  
  7. text.insert(END, "www.c-sharpcorner.com")  
  8. text.pack()  
  9. text.tag_add("here""1.0""1.4")  
  10. text.tag_add("start""1.8""1.13")  
  11. text.tag_config("here", background="yellow", foreground="blue")  
Output-
 
 Option  Description
 bg It is used to have a normal background color.
 bd  Sets border width in pixels. Default is 2.
 cursor Cursor is used to create a cursor in widgets like arrow, circle, dot etc.
exportselection Normally, text selected within a text widget is exported to be the selection in the Window manager. Set exportselection=0, if you don't want that behavior.
font
It is used to change the font style.
fg
It sets normal foreground (text) color of widgets.
height
It is used to define the height of widgets.
highlightbackground
It is used to set background color.
highlightcolor
It changes color of widgets on focus.
highlightthickness
It is used to set focus highlight of widgets on focus
insertbackground
It is used to define color of the insertion cursor. Default is black.
insertborderwidth
It is used to define the size of the 3-D border around the insertion cursor. Default is 0.
insertofftime
It is used to define the cursor blink time
Insertontime
It is used to define the cursor after blink time.
insertwidth
It is used to define insert width.
padx
It is used to add additional padding on left and right of text of widgets
pady
It is used for additional padding above and below text of widgets.
relief
Relief is special type of border. The values are SUNKEN, RAISED, GROOVE and RIDGE.
selectbackground
It is used to set the background color of the selected text.
state It is used to define the state of widgets.
tabs
This option controls how tab characters position text.
width
It is used to define the width of widgets.
xscrollcommand It is used to scroll on define value in x direction
yscrollcommand
It is used to define the scrolling value in y direction
 Summary

In this Chapter, what Text widget is and how to use the property of the widget.