Selection in Tkinter Text widget.
fredrik at pythonware.com
Fri Jun 2 14:17:48 CEST 2006
"Ant" <antroy at gmail.com> wrote:
> I have been trying to select text in a Text widget programmatically. I
> have been trying the following minimal example:
> from Tkinter import *
> def showgui():
> win = Tk()
> area = Text(win, width = 50, height = 20)
> new = """Lots of text here
> and here
> and here..."""
> area.insert("1.0", new)
> area.tag_add(SEL, "1.0", END)
> if __name__ == "__main__":
> The area.tag_add(...) line should - from what I have read in Frederik's
> Intro to Tkinter guide - select all of the text in the text area. It
> doesn't however...
it does, but by default, the selection is only shown for widgets that has the key-
board focus. if you add an explicit focus_set() call, you'll see the selection.
More information about the Python-list