【问题标题】:python tkinter, how to get elements in root/notebook/Frame?python tkinter,如何获取根/笔记本/框架中的元素?
【发布时间】:2021-06-27 08:06:21
【问题描述】:

我使用 tkinter 创建 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

例如: 根 - 笔记本 - - 框架 ------树

所以,我的问题:

如果我获得了root,我如何获得root中的元素?

例如,如何获取 notebook/Frame/tree?

非常感谢您的帮助

【问题讨论】:

    标签: python tkinter treeview


    【解决方案1】:

    试试属性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
    {}
    

    【讨论】:

    • 谢谢。如何从 root.children 获取 tabControl?
    • root.children['!notebook']
    猜你喜欢
    • 2021-10-27
    • 2013-05-07
    • 1970-01-01
    • 2018-04-05
    • 1970-01-01
    • 1970-01-01
    • 2021-01-20
    • 2018-08-19
    • 2023-03-19
    相关资源
    最近更新 更多