【问题标题】:python tkinter treeview set focus to newly inserted itempython tkinter treeview 将焦点设置为新插入的项目
【发布时间】:2019-03-19 07:55:00
【问题描述】:

我正在插入一个新项目,例如:

# Insert new item as child of current item
tree.insert(current_node_iid, 1, text="New note")

我可以将焦点设置在一个项目上:

# Must select and then focus using the iid of an item
tree.selection_set("I001")
tree.focus("I001")

但是如果我插入一个新项目,并且我让 Python 设置新项目的索引,那么我不知道这个新索引,因此我无法将焦点设置在新项目上。

我当然可以指定新项目的 iid,但是我必须检查 iid 是否已被另一个项目使用,我不知道该怎么做。

如何将焦点设置在新项目上?

感谢任何帮助。提前谢谢。

【问题讨论】:

    标签: python tkinter focus


    【解决方案1】:

    只需为您的tree.insert 命令定义一个变量。

    a = tree.insert(current_node_iid, 1, text="New note")
    print (a)
    

    结果:

    I001
    

    【讨论】:

    • 再次感谢您的帮助,Henry :) 我会试一试.....
    • 效果很好!再次感谢。
    • 我以为我可以选择你的答案作为我问题的答案,但我似乎无法这样做:(
    猜你喜欢
    • 1970-01-01
    • 2017-05-26
    • 1970-01-01
    • 1970-01-01
    • 2012-11-17
    • 2015-10-11
    • 2013-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多