Back to index

python3.2  3.2.2
Classes | Functions | Variables
tkinter.filedialog Namespace Reference

Classes

class  FileDialog
class  LoadFileDialog
class  SaveFileDialog
class  _Dialog
class  Open
class  SaveAs
class  Directory

Functions

def askopenfilename
def asksaveasfilename
def askopenfilenames
def askopenfile
def askopenfiles
def asksaveasfile
def askdirectory
def test

Variables

dictionary dialogstates = {}

Detailed Description

File selection dialog classes.

Classes:

- FileDialog
- LoadFileDialog
- SaveFileDialog

This module also presents tk common file dialogues, it provides interfaces
to the native file dialogues available in Tk 4.2 and newer, and the
directory dialogue available in Tk 8.3 and newer.
These interfaces were written by Fredrik Lundh, May 1997.

Function Documentation

Definition at line 428 of file filedialog.py.

00428 
00429 def askdirectory (**options):
00430     "Ask for a directory, and return the file name"
00431     return Directory(**options).show()
00432 
00433 
00434 
00435 # --------------------------------------------------------------------
00436 # test stuff

Here is the call graph for this function:

def tkinter.filedialog.askopenfile (   mode = "r",
  options 
)

Definition at line 395 of file filedialog.py.

00395 
00396 def askopenfile(mode = "r", **options):
00397     "Ask for a filename to open, and returned the opened file"
00398 
00399     filename = Open(**options).show()
00400     if filename:
00401         return open(filename, mode)
00402     return None

Here is the call graph for this function:

Definition at line 374 of file filedialog.py.

00374 
00375 def askopenfilename(**options):
00376     "Ask for a filename to open"
00377 
00378     return Open(**options).show()

Here is the call graph for this function:

Here is the caller graph for this function:

Ask for multiple filenames to open

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

Definition at line 384 of file filedialog.py.

00384 
00385 def askopenfilenames(**options):
00386     """Ask for multiple filenames to open
00387 
00388     Returns a list of filenames or empty list if
00389     cancel button selected
00390     """
00391     options["multiple"]=1
00392     return Open(**options).show()
00393 
00394 # FIXME: are the following  perhaps a bit too convenient?

Here is the call graph for this function:

Here is the caller graph for this function:

def tkinter.filedialog.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

Definition at line 403 of file filedialog.py.

00403 
00404 def askopenfiles(mode = "r", **options):
00405     """Ask for multiple filenames and return the open file
00406     objects
00407 
00408     returns a list of open file objects or an empty list if
00409     cancel selected
00410     """
00411 
00412     files = askopenfilenames(**options)
00413     if files:
00414         ofiles=[]
00415         for filename in files:
00416             ofiles.append(open(filename, mode))
00417         files=ofiles
00418     return files
00419 

Here is the call graph for this function:

def tkinter.filedialog.asksaveasfile (   mode = "w",
  options 
)

Definition at line 420 of file filedialog.py.

00420 
00421 def asksaveasfile(mode = "w", **options):
00422     "Ask for a filename to save as, and returned the opened file"
00423 
00424     filename = SaveAs(**options).show()
00425     if filename:
00426         return open(filename, mode)
00427     return None

Here is the call graph for this function:

Definition at line 379 of file filedialog.py.

00379 
00380 def asksaveasfilename(**options):
00381     "Ask for a filename to save as"
00382 
00383     return SaveAs(**options).show()

Here is the call graph for this function:

Here is the caller graph for this function:

Simple test program.

Definition at line 437 of file filedialog.py.

00437 
00438 def test():
00439     """Simple test program."""
00440     root = Tk()
00441     root.withdraw()
00442     fd = LoadFileDialog(root)
00443     loadfile = fd.go(key="test")
00444     fd = SaveFileDialog(root)
00445     savefile = fd.go(key="test")
00446     print(loadfile, savefile)
00447 
00448     # Since the file name may contain non-ASCII characters, we need
00449     # to find an encoding that likely supports the file name, and
00450     # displays correctly on the terminal.
00451 
00452     # Start off with UTF-8
00453     enc = "utf-8"
00454     import sys
00455 
00456     # See whether CODESET is defined
00457     try:
00458         import locale
00459         locale.setlocale(locale.LC_ALL,'')
00460         enc = locale.nl_langinfo(locale.CODESET)
00461     except (ImportError, AttributeError):
00462         pass
00463 
00464     # dialog for openening files
00465 
00466     openfilename=askopenfilename(filetypes=[("all files", "*")])
00467     try:
00468         fp=open(openfilename,"r")
00469         fp.close()
00470     except:
00471         print("Could not open File: ")
00472         print(sys.exc_info()[1])
00473 
00474     print("open", openfilename.encode(enc))
00475 
00476     # dialog for saving files
00477 
00478     saveasfilename=asksaveasfilename()
00479     print("saveas", saveasfilename.encode(enc))

Here is the call graph for this function:


Variable Documentation

Definition at line 23 of file filedialog.py.