Dynamic text color
mackrackit at gmail.com
Fri Jan 8 20:55:26 CET 2010
On Fri, Jan 8, 2010 at 12:28 PM, MRAB <python at mrabarnett.plus.com> wrote:
> Dave McCormick wrote:
>> On Wed, Jan 6, 2010 at 9:18 AM, John Posner <jjposner at optimum.net<mailto:
>> jjposner at optimum.net>> wrote:
>> On Tue, 05 Jan 2010 16:54:44 -0500, Dave McCormick
>> <mackrackit at gmail.com <mailto:mackrackit at gmail.com>> wrote:
>> But it is not what I am wanting. I first thought to make it look
>> for a space but that would not work when a single character like
>> "#" is to be colored if there is a "string" of them. Or if all
>> of the characters between quotes are to be colored.
>> Regular expressions are good at handling searches like:
>> * all the characters between quotes
>> * the two-character string "do", but only if it's a complete word
>> -- http://mail.python.org/mailman/listinfo/python-list
>> I need another hint...
>> Been doing some reading and playing and it looks like
>> is what I need. But I can not figure out how to pass a variable between
>> If the word in question is between the "\b \b" and in the list then it
>> works like I want it to.
>> The below does not work.
>> greenList_regexp = "|".join(greenList)
>> for matchobj in re.finditer(r'\bgreenList_regexp\b', complete_text):
>> start,end = matchobj.span()
>> The regex r'\bgreenList_regexp\b' will match the string
> 'greenList_regexp' if it's a whole word.
> What you mean is "any of these words, provided that they're whole
> words". You'll need to group the alternatives within "(?:...)", like
> r'\b(?:' + greenList_regexp + ')\b'
> Thanks but that did not work either.
Maybe I have something else wrong too?
complete_text = Tbox.get("1.0", END)
greenList = "green grass".split()
greenList_regexp = "|".join(greenList)
for matchobj in re.finditer(r'\b(?:' + greenList_regexp + ')\b',
start,end = matchobj.span()
Tbox.tag_add("green", "1.0 + %d chars" % start,"1.0 + %d chars" %
The words "green" and "grass" do not turn green.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list