tabbing through Tk Text widgets

E

Elaine Jackson

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
 
E

Eric Brunel

Elaine said:
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/tkinter/introduction/x9374-event-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()
 
E

Elaine Jackson

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

| 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/tkinter/introduction/x9374-event-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
|
 

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

No members online now.

Forum statistics

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

Latest Threads

Top