How to move insert to position in Text widget (Tkinter)

H

Harlin Seritt

I am working on a Find Text dialog box. Once you find a string in a
Text widget, how do you at least move the cursor to that index
(position)? Even better how can one 'select' the string one finds?

---code---
def searchText():
while 1:
pos = self.mainEdit.search(findString.get(), 1.0,
stopindex=END)
if not pos:
break

print pos
start = pos + "+1c"
break
---end code---

thanks,

Harlin Seritt
 
F

Fredrik Lundh

Harlin said:
I am working on a Find Text dialog box. Once you find a string in a
Text widget, how do you at least move the cursor to that index
(position)?

widget.mark_set(INSERT, pos)
Even better how can one 'select' the string one finds?

widget.tag_add(SEL, pos, endpos)

to remove an existing selection, use

widget.tag_remove(SEL, 1.0, END)

</F>
 
H

Harlin Seritt

Frederik,

Thanks! Just looking at your site (effbot and pythonware). I don't know
what I'd do without it!

Cheers,

Harlin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top