469,275 Members | 1,675 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

tabbing through Tk Text widgets

I've got a Tk window with a large number of Text widgets, and I'd like to have
the TAB key move focus from one Text widget to the next. Unfortunately I can't
find the recipe. Can anybody help?

Peace
Jul 18 '05 #1
2 5097
Elaine Jackson wrote:
I've got a Tk window with a large number of Text widgets, and I'd like to have
the TAB key move focus from one Text widget to the next. Unfortunately I can't
find the recipe. Can anybody help?

Peace


See methods tk_focusNext & tk_focusPrev in
http://www.pythonware.com/library/tk...processing.htm

Here is an example:

----------------------------------------------------
from Tkinter import *

root = Tk()

t1 = Text(root)
t1.pack(side=TOP)

t2 = Text(root)
t2.pack(side=TOP)

def focusNext(widget):
widget.tk_focusNext().focus_set()
return 'break'

def focusPrev(widget):
widget.tk_focusPrev().focus_set()
return 'break'

for t in (t1, t2):
t.bind('<Tab>', lambda e, t=t: focusNext(t))
t.bind('<Shift-Tab>', lambda e, t=t: focusPrev(t))

t1.focus_set()

root.mainloop()
----------------------------------------------------

HTH
--
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com

Jul 18 '05 #2
Thanks for your help. This post sat around for so long without a response that I
worried people perceived it as a "dumb question".

"Eric Brunel" <er*********@despammed.com> wrote in message
news:cd**********@news-reader5.wanadoo.fr...
| Elaine Jackson wrote:
| > I've got a Tk window with a large number of Text widgets, and I'd like to
have
| > the TAB key move focus from one Text widget to the next. Unfortunately I
can't
| > find the recipe. Can anybody help?
| >
| > Peace
|
| See methods tk_focusNext & tk_focusPrev in
|
http://www.pythonware.com/library/tk...-processing.ht
m
|
| Here is an example:
|
| ----------------------------------------------------
| from Tkinter import *
|
| root = Tk()
|
| t1 = Text(root)
| t1.pack(side=TOP)
|
| t2 = Text(root)
| t2.pack(side=TOP)
|
| def focusNext(widget):
| widget.tk_focusNext().focus_set()
| return 'break'
|
| def focusPrev(widget):
| widget.tk_focusPrev().focus_set()
| return 'break'
|
| for t in (t1, t2):
| t.bind('<Tab>', lambda e, t=t: focusNext(t))
| t.bind('<Shift-Tab>', lambda e, t=t: focusPrev(t))
|
| t1.focus_set()
|
| root.mainloop()
| ----------------------------------------------------
|
| HTH
| --
| - Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
| PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
|
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by William Gill | last post: by
1 post views Thread by Tom | last post: by
reply views Thread by Mike Walters | last post: by
6 posts views Thread by Doug Bell | last post: by
10 posts views Thread by jp | last post: by
7 posts views Thread by Gandalf | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.