Selection in Tkinter Text widget.
Fredrik Lundh
fredrik at pythonware.com
Fri Jun 2 08:17:48 EDT 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)
> area.pack()
>
> new = """Lots of text here
> and here
> and here..."""
> area.insert("1.0", new)
>
> area.tag_add(SEL, "1.0", END)
area.focus_set()
> win.mainloop()
>
> if __name__ == "__main__":
> showgui()
> #==================================
>
> 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.
</F>
More information about the Python-list
mailing list