Tkinter & all widgets

Matthew Dixon Cowles matt at mondoinfo.com
Sun Oct 14 19:39:42 EDT 2001


On Sun, 14 Oct 2001 22:30:08 GMT, David Ashe <dash at home.com> wrote:
>Is there a way to get the complete list of widgets in a window as a
>list, array, dictionary, or tuple?  I seem to recall this was
>possible under tcl, but I can't remember how.

David,
Yes, you can use the children attribute:

>>> from Tkinter import *
>>> r=Tk()
>>> l=Label(r,text="foo")
>>> l.pack()
>>> e=Entry(r)
>>> e.pack()
>>> r.children
{'136255148': <Tkinter.Label instance at 0x81f16ac>,
 '136377364': <Tkinter.Entry instance at 0x820f414>}
>>> r.children.values()
[<Tkinter.Label instance at 0x81f16ac>, <Tkinter.Entry instance at 0x820f414>]
>>> r.children.values()[0].configure(text="bar")

Regards,
Matt



More information about the Python-list mailing list