Tkinter - how to open recent files? Tkinter - how to open recent files? tkinter tkinter

Tkinter - how to open recent files?


the following works:

...

    for name in ('file1.txt', 'file2.txt', 'file3.txt'):        recentMenu.add_command(label=name, command=self.load_file(name))

...

def load_file(self, f):    def fun():        print f    return fun

In your version, at the moment, when you call the callback function, name refers to the instance file3.txt. In my version, the instances file1.txt, file2,txt, and so on, are captured inside closures (not strictly a closure, but very similar).

See closures in SO.