Search code examples
pythontkintertreeview

python tkinter, how to get elements in root/notebook/Frame?


I use tkinter to create gui

1、root = tk.Tk()

2、tabControl = ttk.Notebook(root)
//create one notebook

3、tab1 = tk.Frame(tabControl, bg = 'blue', width = '400')
     tabControl.add(tab1, text = 'information')
//create one Frame in notebook

4、tree = ttk.Treeview(tab1,columns=ac)
//create one tree view in Frame

such as: root --notebook ----Frame ------tree

So, my question:

If I get root, How can I get elements in root?

For example, How can I get notebook/Frame/tree?

Thanks very much for your help


Solution

  • Try attribute children

    >>> root.children
    {'!notebook': <tkinter.ttk.Notebook object .!notebook>}
    >>> tabControl.children
    {'!frame': <tkinter.Frame object .!notebook.!frame>}
    >>> tab1.children
    {'!treeview': <tkinter.ttk.Treeview object .!notebook.!frame.!treeview>}
    >>> tree.children
    {}