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

Discussion in 'Python' started by Harlin Seritt, Mar 25, 2005.

  1. 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
     
    Harlin Seritt, Mar 25, 2005
    #1
    1. Advertising

  2. Harlin Seritt wrote:

    >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>
     
    Fredrik Lundh, Mar 25, 2005
    #2
    1. Advertising

  3. Frederik,

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

    Cheers,

    Harlin
     
    Harlin Seritt, Mar 25, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex9968
    Replies:
    0
    Views:
    596
    Alex9968
    Mar 19, 2008
  2. Alex9968
    Replies:
    0
    Views:
    1,601
    Alex9968
    Mar 19, 2008
  3. Frederic Rentsch
    Replies:
    0
    Views:
    266
    Frederic Rentsch
    Jul 8, 2012
  4. Terry Reedy
    Replies:
    15
    Views:
    663
    Frederic Rentsch
    Jul 16, 2012
  5. Frederic Rentsch
    Replies:
    0
    Views:
    454
    Frederic Rentsch
    Jul 9, 2012
Loading...

Share This Page