tab order for Tkinter widgets
Martin Franklin
martin.franklin at westgeo.com
Mon Feb 18 10:04:36 EST 2002
Laura Creighton wrote:
> I thought that the order in which you tabbed through widgets was the
> order in which you gridded them (assuming you are using the grid manager).
> I have a bunch of widgets that know what row and what column they are
> to be gridded in, but I cannot guarantee what order I can get them out
> of the database.
>
> So in the middle of a loop I have:
>
> decorated.append((d['managerArgs']['row'],
> d['managerArgs']['column'],
> d['managerArgs'], widget ))
>
> then at the bottom I can do
>
> decorated.sort()
> for junk, junk, args, widget in unordered:
> widget.grid(args)
>
> They are all gridding nicely. The sort works great as well. And
> tabbing gets you randomly flopping from one entry field to another
> same as always. Clearly there is something else I need to do to get
> my widgets to tab in the correct order. What?
>
> Thanks very much,
> Laura Creighton
>
>
Laura,
This simple example may help??
from Tkinter import *
root=Tk()
edict={}
top_simple=Toplevel()
top_simple.title('Simple.....')
for row in range(10):
for col in range(10):
edict[row, col]=(row, col)
e=Entry(top_simple)
e.grid(row=row, col=col)
# now get the coords out 'randomly'.....
root.title('Random')
for row, col in edict.keys():
e=Entry(root)
e.grid(row=row, col=col)
# this time sort the 'keys' then grid em!
top_sorted=Toplevel()
top_sorted.title('Sorted')
keys=edict.keys()
keys.sort()
for row, col in keys:
e=Entry(top_sorted)
e.grid(row=row, col=col)
root.mainloop()
More information about the Python-list
mailing list