Home > Net >  How can I check if a TextArea string is within a tag?
How can I check if a TextArea string is within a tag?

Time:06-04

I am creating a rudimentary text editor with Python using TKinter. I have the basic menu functions and text area down, and I would like to have built in syntax highlighting (specifically for keywords in MS batch scripts).

How can I detect if a substring (e.g. a keyword) has already had a format text tag applied to it? Where do I start?

CodePudding user response:

How can I detect if a substring (e.g. a keyword) has already had a format text tag applied to it? Where do I start?

You can use the tag_names method to get a list of all tags for a specific index in a text widget. If you have a range of characters, you can iterate over each character to get all of the tags in the range.

tags = text.tag_names("1.5")
  • Related