newbie: selecting text by script in Tkinter fails
Martin Franklin
martin.franklin at westgeo.com
Tue Nov 6 16:54:32 EST 2001
Hi!,
Johnny deBris wrote:
> Hello!!
>
> I have a question about selecting text in a Tkinter Text-widget using
> the tag_remove and tag_add-methods: there is a small explanation on
> how it should be done in 'an Introduction to Tkinter', but I cannot
> get the work done the way the author proposes
>
(http://www.pythonware.com/library/tkinter/introduction/x8369-methods.htm).
> Can anybody tell me how I can select a piece of text from script? I'm
> working on a texteditor in Python, and this is part of a search-option
> I would like to add. For people who think they're suffering from
> deja-vu or something: I have posted a question quite similar to this
> one a few days ago, but no-one seemed to be able to or want to answer.
> (maybe a classical case of RTFM? If so, please tell me where to find
> that FM!! :)
>
> Thanx again,
>
> Guido Wesdorp
>
Here are a couple of functions that I user to 'show' my ;found' text
def find_text(self):
self.parent.textarea.tag_delete("found")
pat=self.pattern.get()
if not pat:
return
self.found=self.parent.textarea.search(pat, "insert")
if self.found:
self.show()
def show(self):
line, start = map(int, self.found.split('.'))
end=start+len(self.pattern.get())
self.parent.textarea.tag_add("found", "%d.%d" %(line,
start), "%d.%d" %(line, end))
self.parent.textarea.tag_config("found", background='navy',
foreground='white')
self.parent.textarea.mark_set("insert", "%d.%d" %(line, end+1))
self.parent.textarea.see("%d.%d" %(line, start))
self.parent.textarea.update()
HTH
Martin
More information about the Python-list
mailing list