如何使ttk treeview行/项充当按钮?

2024-10-02 00:33:56 发布

您现在位置:Python中文网/ 问答频道 /正文

请不要使用Class,unuyu init,uuuyu,等等,因为这些都超出了我的知识和理解范围。基本上,如果有人能告诉我如何在相同的空白/缩进级别的代码中做到这一点,我将不胜感激。在

在windows上使用python3.4.3

谢谢


Tags: 代码initwindows级别空白classunuyuuuuyu
1条回答
网友
1楼 · 发布于 2024-10-02 00:33:56

oystein hr为您提供解决方案,您可以使用它作为正常功能。在

示例基于Byan Oakley示例代码:
https://stackoverflow.com/a/3794505/1832058

布莱恩·奥克利建议使用<<TreeviewSelect>>https://stackoverflow.com/a/12064135/1832058

import tkinter as tk
from tkinter import ttk

def OnDoubleClick(event):
    item = tree.selection()
    print('item:', item)
    print('event:', event)
    item = tree.selection()[0]

    print("you clicked on", tree.item(item,"text"))

root = tk.Tk()
tree = ttk.Treeview()
tree.pack()

for i in range(10):
    tree.insert("", "end", text="Item %s" % i)

#tree.bind("<Double-1>", OnDoubleClick) # double click
#tree.bind("<Button-1>", OnDoubleClick) # single click
tree.bind("<<TreeviewSelect>>", OnDoubleClick) # single click, without "index out of range" error

root.mainloop()

没有行“充当按钮”,因为您可以单击它来运行函数。在

相关问题 更多 >

    热门问题