tkFileDialog.askopenfilename

S

Sonia Rovner

tkFileDialog.askopenfilename only allows you to open an existing file.
I want to allow my users to enter a new filename in the dialog box.
Can anyone help?
 
P

Peter Otten

Sonia said:
tkFileDialog.askopenfilename only allows you to open an existing file.
I want to allow my users to enter a new filename in the dialog box.
Can anyone help?

Seems you are out of luck:

"The procedures tk_getOpenFile and tk_getSaveFile pop up a dialog box for
the user to select a file to open or save. The tk_getOpenFile command is
usually associated with the Open command in the File menu. Its purpose is
for the user to select an existing file only. If the user enters an
non-existent file, the dialog box gives the user an error prompt and
requires the user to give an alternative selection. If an application
allows the user to create new files, it should do so by providing a
separate New menu command. "

Quoted from http://www.tcl.tk/man/tcl8.5/TkCmd/getOpenFile.htm

Peter
 
M

Martin Franklin

Sonia said:
tkFileDialog.askopenfilename only allows you to open an existing file.
I want to allow my users to enter a new filename in the dialog box.
Can anyone help?

tkFileDialog.saveasfilename could be what you are looking for...

trusty pydoc comes to the rescue...

$ pydoc tkFileDialog

<snip>

FUNCTIONS
askdirectory(**options)
Ask for a directory, and return the file name


askopenfile(mode='r', **options)
Ask for a filename to open, and returned the opened file


askopenfilename(**options)
Ask for a filename to open


askopenfilenames(**options)
Ask for multiple filenames to open


Returns a list of filenames or empty list if
cancel button selected


askopenfiles(mode='r', **options)
Ask for multiple filenames and return the open file
objects


returns a list of open file objects or an empty list if
cancel selected


asksaveasfile(mode='w', **options)
Ask for a filename to save as, and returned the opened file

asksaveasfilename(**options)
Ask for a filename to save as


HTH
Martin
 
R

Russell E. Owen

tkFileDialog.askopenfilename only allows you to open an existing file.
I want to allow my users to enter a new filename in the dialog box.
Can anyone help?

Try:
tkFileDialog.asksaveasfilename

By the way, your installation probably has the source code; if so, this
file is in <python root>/lib/lib-tk/ (if you don't have source it can be
downloaded from python.org and individual files can be examined at
sourceforge). I've found looking at the Tkinter-related files quite
useful for figuring out stuff like this. In particular, I've found it
helpful to look through tkFileDialog.py, tkFont.py and Tkinter.py.

-- Russell
 
S

Sonia Rovner

Peter Otten said:
Seems you are out of luck:

"The procedures tk_getOpenFile and tk_getSaveFile pop up a dialog box for
the user to select a file to open or save. The tk_getOpenFile command is
usually associated with the Open command in the File menu. Its purpose is
for the user to select an existing file only. If the user enters an
non-existent file, the dialog box gives the user an error prompt and
requires the user to give an alternative selection. If an application
allows the user to create new files, it should do so by providing a
separate New menu command. "

Quoted from http://www.tcl.tk/man/tcl8.5/TkCmd/getOpenFile.htm

Peter

Thank you very much.

Sonia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top