- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 highlight the current line of a Text widget in Tkinter?
We can use the Tkinter text widget to accept multiline user input. We can insert text, display information, and get the output from the text widget.
To highlight the currently selected text in a text widget, we can use the tag_add() method that adds a tag in the current text only.
# Import the required library from tkinter import * # Create an instance of tkinter frame win=Tk() # Set the geometry win.geometry("700x350") # Add a text widget text=Text(win, width=80, height=15, font=('Calibri 12')) # Set default text for text widget text.insert(INSERT, "Tkinter is a Python Library to create GUI-based 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") text.pack() win.mainloop()
Running the above code will display a window with a text widget having a highlighted text in it.
- Related Articles
- How to highlight text in a tkinter Text widget?
- How to get the current length of the Text in a Tkinter Text widget?
- How to force Tkinter text widget to stay on one line?
- How to clear the contents of a Tkinter Text widget?
- How to create hyperlink in a Tkinter Text widget?
- How do I center the text in a Tkinter Text widget?
- Get the text of a button widget in Tkinter
- How to take input in a text widget and display the text in tkinter?
- How to attach a Scrollbar to a Text widget in Tkinter?
- How to attach a vertical scrollbar in Tkinter text widget?
- How to erase everything from a Tkinter text widget?
- How to change the color of certain words in a Tkinter text widget?
- How to make the Tkinter text widget read only?
- How to erase everything from the Tkinter text widget?
- How to insert a temporary text in a tkinter Entry widget?