Python 3 Tkinter Highlight Text With Background Color on Button Click Event GUI Desktop App Full Project For Beginners



#Import tkinter library
from tkinter import *
#Create an instance of tkinter frame
win= Tk()
#Define a function to highlight the text
def add_highlighter():
   text.tag_add("start", "1.11","1.17")
   text.tag_config("start", background= "black", foreground= "white")
#Create a Tex Field
text= Text(win);
text.insert(INSERT, "Hey there! Howdy?")
#Create a Button to highlight text
Button(win, text= "Highlight", command= add_highlighter).pack()

Leave a Reply