I have an entry widget where the user can type in a file location, and underneath that a "save" button and a "load" button. Depending on which button is clicked, the file specified in the entry widget is either opened for writing, or for reading.
This all works fine and dandy.
Now I want to add a "browse" button, which the user can click to open a file dialog to select a file. When a file is selected, the filename is copied into the entry. From there on, the save and load buttons should work fine.
However, I can't figure out how to get the file dialog to work for both reading a file and writing. I can't use tkFileDialog.asksaveasfilename
because that's going to complain to the user if a file already exists (which, if the user intends to "load", it should) and the tkFileDialog.askloadasfilename
function doesn't let the user select a file which doesn't exist yet (which, if the user intends to "save", should be fine as well).
Is it possible to create a dialog which displays neither of these functionalities?