I am new to python. I use python 3.8 version. I try to iterate over the words and lines in the text box and need a way to highlight the words without highlighting the spaces. Since, the get() methods in tkinter takes index starting from 1.0 for 1st line, from 2.0 for 2nd line and so on.., i try to convert the original index with some calculations. But i cannot highlight all the text.
Thanks in advance!!
from tkinter import *
import tkinter
core = Tk()
scroll = Scrollbar(core)
txt = Text(core, height = 35, width =85, yscrollcommand = scroll.set, \
font =('bold',15),cursor="plus #aab1212" \
)
# txt1.place(x=980, y=37)
scroll.config(command = txt.yview)
# scroll1.config(command = txt.xview)
scroll.pack(side=RIGHT, fill=Y)
txt.pack(side="right")
def get_index():
l = []
for i,w in enumerate(txt.get('1.0', 'end-1c').splitlines()):
l.append(w)
i = i + 1.1
print(i,w)
if i < 10:
x = 1 + float(0) / 10
txt.tag_add("start", x)
txt.tag_config("start", background= "yellow", foreground= "black")
print(l)
for w,i in enumerate(l):
print(i)
button1 = Button(text = 'index',command=get_index)
button1.place(x = 30, y = 50, height = 30, width = 150)
core.mainloop()