Home > database >  tk.Text: Making image_create() images searchable by RegEx
tk.Text: Making image_create() images searchable by RegEx

Time:07-15

I'm already pretty sure this isn't possible, but maybe someone here is really clever and knows a way. When you use create_image in a tk.Text, tkdocs states it is treated as any other character. This is barely true, though. It moves along with it's surrounding characters and you can use BackSpace on it, but other than that it is not a character, at all. It has zero length and nothing that it can be identified with in a regular expression. That is, I believe it can't be identified in a re, and that is the entire point of my actual question.

Is it possible to give the results of create_image some kind of an identifier that can be caught in a regular expression? Something like [^every legitimate possibility] is not going to work. I say this because you can catch the image with ., so you probably could catch it, by it not being "everything else". Unfortunately, clunky methods like that are really not going to work for my needs.

If it helps to understand the specific problem. I have multiple faux-carets in my widget during certain behaviors. I am also using idlelib to do syntax-highlighting. idlelib does not like my faux-carets. I have semi-solved this problem without any regex. I believe I could completely solve it if I could describe the faux-caret in regex some kind of semi-sane way.

CodePudding user response:

It actually is possible. You have to apply the image as fgstipple in a tag instead of using image_create. Then you can apply the tag to any imaginable character that regex recognizes. Instead of inserting images, you insert the desired dummy character (presumably some never-used whitespace character (U 200A)?), and tag it.

Alternately, since you are dealing with carets, you could just tag the character before the caret, create no new characters, and skip the regex.

  • Related