I'm developing an interface with Tkinter that makes use of a file dialog with tkFileDialog
.
I want to run a function immediately after the user has chosen a file from the dialog box.
With buttons, we have a command keyword from which we run a function (usually named def callback():
). Is there a similar keyword for the file dialog or askopenfilename
?
The
askopenfilename
function consists of the opening of a dialog, and returns immediately when the latter was closed (including when a file has been selected). Put your callback right after this function to have it run right after the closing of the dialog.For instance:
will open a file selection dialog, and as soon as the user has selected a file, the corresponding object that was created will be printed out.