I'm writing a simple script that creates a ttk Treeview
(that acts as a table) and, when you double-click it, it opens a file (with the path saved in the dictionary). However, when you double-click a row you'll get this error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:UsersMaicolAppDataLocalProgramsPythonPython36lib kinter\__init__.py",
line 1699, in __call__
return self.func(*args)
File "C:UsersMaicolDocumentsProjectsApp_WINDOWSSchool_Life_Diary
ote.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>'
The problem is this code:
t.bind("<Double-1>", lambda f=nt[x]["URIallegato"]: os.startfile(str(f)))
that allows the double-clicking and opening of the file.
Here is the full Treeview
code:
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)))
See Question&Answers more detail:os