I'd like to create a tag for each word in my text widget.
This is my starting code.
import tkinter as tk
from tkinter import ttk
class text_editor(ttk.Frame):
def __init__(self, parent, entry_initial_value='...'):
ttk.Frame.__init__(self, parent)
indexes = [0, 1]
self.columnconfigure(indexes, weight=1)
self.rowconfigure(indexes, weight=1)
self.text = tk.Text(self)
my_text = "one one\ntwo two\nthree three"
self.text.insert('1.0', my_text)
#row.char
self.text.grid(column=0, row=0)
class App(tk.Tk):
# costruttore
def __init__(self):
super().__init__()
# configure the root window
self.title('My App')
self.geometry('300x50')
c = text_editor(self)
c.pack()
if __name__ == "__main__":
app = App()
app.mainloop()
Is there an easy way to handle this problem or is the only way to handle the coordinates of each word, specifying for each word the row it belongs to and the starting and ending index?
p.s. are there any other ways to select the characters that belong to the tag other than the coordinate system of the raw.char type? like in this example
text.tag_add('highlightline', '5.0', '6.0')