您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python tkinter树获取选定的项目值

python tkinter树获取选定的项目值

获取所选项目及其所有属性和值,可以使用以下item方法

def selectItem(a):
    curItem = tree.focus()
    print tree.item(curItem)

这将输出一个词典,您可以从中轻松检索单个值:

{'text': 'Name', 'image': '', 'values': [u'Date', u'Time', u'Loc'], 'open': 0, 'tags': ''}

另外请注意,回调将被执行 之前, 在树中的焦点变了,即你将获得该项目 您点击的新项目之前选择。解决此问题的一种方法是改用事件类型ButtonRelease

tree.bind('<ButtonRelease-1>', selectItem)
python 2022/1/1 18:47:31 有334人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶