[Tkinter-discuss] How can I edit a string inside a textbox?

Alex Garipidis n3atione at hotmail.com
Thu Dec 6 17:37:16 CET 2007


> to find things in a text widget, use the "search" method:> > pos = text.search(string, start)> > where "string" is the string you want to search for, and start is the > starting position (e.g. 1.0 or INSERT).> > to search for things that match "@word", where "word" is an arbitrary > string of letters or digits, you can use a regular expression, e.g.> > pos = text.search("@\w+", 1.0, regexp=True)> > search only returns where the match begins; to find the end of "@word", > you can search from the given position to the first thing that isn't a > word character:> > end = text.search("\W", pos + " 1 char", regexp=True)> > to change the appearance of a block of text, register the style using > tag_config, and then use tag_add to apply the style tag to the block, e.g.:> > # do this when you create the widget> text.tag_config("mystyle", foreground="red")> > # do this to apply this style to a range of text> text.tag_add("mystyle", pos, end)> > hope this helps!> > </F>> > _______________________________________________> Tkinter-discuss mailing list> Tkinter-discuss at python.org> http://mail.python.org/mailman/listinfo/tkinter-discuss
 
 
Hello Fredric,
 
Thank you for your answer. I am experiencing some problems with the code you suggested. The 
 
end = text.search("\W", pos + " 1 char", regexp=True)
gives me this as a result: TclError: bad text index " 1 char". I tried some other options for the " 1 char" 
part but the result was the same. Any ideas? I am using Windows XP and Python 2.5.
 
Thanks again for the answer, 
 
Alex
_________________________________________________________________
Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy!
http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20071206/15b163e7/attachment.htm 


More information about the Tkinter-discuss mailing list