【发布时间】:2017-09-30 18:55:50
【问题描述】:
我正在编写一个简单的脚本来创建一个 ttk Treeview(充当表格),当您双击它时,它会打开一个文件(路径保存在字典中)。但是,当您双击一行时,您会收到此错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Maicol\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py",
line 1699, in __call__
return self.func(*args)
File "C:\Users\Maicol\Documents\Projects\App_WINDOWS\School_Life_Diary\note.py",
line 195, in <lambda>
lambda f=nt[x]["URIallegato"]: os.startfile(str(f)))
FileNotFoundError: [WinError 2] Can't find the specified file: '<ButtonPress event state=Mod1 num=1 x=677 y=37>'
问题是这段代码:
t.bind("<Double-1>", lambda f=nt[x]["URIallegato"]: os.startfile(str(f)))
允许双击打开文件。
这是完整的Treeview 代码:
t=Treeview(w)
t.pack(padx=10,pady=10)
for x in list(nt.keys()):
t.insert("",x,text=nt[x]["allegati"])
if nt[x]["allegati"]!="":
t.bind("<Double-1>",
lambda f=nt[x]["URIallegato"]: os.startfile(str(f)))
【问题讨论】:
标签: python tkinter treeview ttk