0

i am trying to program text editor by using tkinter. this is the mark function:

self.text.tag_add("Mark",tk.SEL_FIRST,tk.SEL_LAST)
self.text.tag_config("Mark",background="yellow",foreground="black")

and this is the unmark function

self.text.tag_add("UnMark",tk.SEL_FIRST,tk.SEL_LAST)
self.text.tag_config("UnMark",background="white",foreground = "black")

but the problem is when i mark the text and then unmark it, i cant mark it again. the mark function dont work when i try to mark the text again that i unmarked it.

1 Answers1

0

The reason is because the "UnMark" tag has a higher priority than the "Mark" tag. You can add the "Mark" tag, but the configuration of "UnMark" takes precedence.

I recommend instead of an "UnMark" tag, you simply remove the "Mark" tag when you don't want something to be marked.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • There is a way to get the position of a word without use sel_first? – Ofek Rozenkrantz Aug 25 '18 at 17:54
  • Get the position by char or something instead of sel_first, for the “config” function – Ofek Rozenkrantz Aug 25 '18 at 18:11
  • @OfekRozenkrantz: I don't understand your question. `sel_first` is for finding the start of the selection. That might be a word or it might not be a word. The text widget has the ability to search, via the `search` method. I don't know what finding a word has to do with adding and removing tags, which is what this question was about. – Bryan Oakley Aug 25 '18 at 18:52
  • Thank you for quick reply to me,the information of search methon was useful to me. i decided add a tag for each character, and remove the tag for each character that selected. i used the search method for find the index of each char that selected. – Ofek Rozenkrantz Aug 26 '18 at 00:42