- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Add advanced features to a tkinter Text widget
Tkinter text widget is much more than just a multiline text editor. It is useful for many applications where user interaction is required.
In order to configure the text widget, tkinter provides many functions and methods. Some of the features that we can add to style the text widgets are: changing the font-family, background-color, foreground-color, adding and selecting a particular text, changing font-size, and many more.
In this example, we will see how we can add different features to a particular text widget,
#Import tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry of tkinter window win.geometry("750x250") #Create a text widget text= Text(win, width= 50, height=14) #Set default text for text widget text.insert(INSERT, "Tkinter is a Python Library which is used to create various types of applications.") text.insert(END, "Learning Tkinter is Awesome!!") #Select Text by adding tags text.tag_add("start", "1.0","1.7") text.tag_configure("start", background= "OliveDrab1", foreground= "black") #Configure the Text Style text.configure(font=('Times New Roman',15)) text.pack() win.mainloop()
Running the above code will display a window containing a text widget with some features and properties.
- Undo and redo features in a Tkinter Text widget
- How to highlight text in a tkinter Text widget?
- Printing a list to a Tkinter Text widget
- Underline Text in Tkinter Label widget
- How to erase everything from a Tkinter text widget?
- How to create hyperlink in a Tkinter Text widget?
- How to add a column to a Tkinter TreeView widget?
- How to attach a Scrollbar to a Text widget in Tkinter?
- How do I center the text in a Tkinter Text widget?
- How to set default text for a Tkinter Entry widget?
- How to clear the contents of a Tkinter Text widget?
- How to attach a vertical scrollbar in Tkinter text widget?
- How to insert a temporary text in a tkinter Entry widget?
- Get the text of a button widget in Tkinter
- Select all text in a Text widget using Python 3 with tkinter