enabling multiple file types

Posted by dbrien on 2016-07-21 09:45

Using the latest versions of ActiveState TCL (8.6.4.1 or 8.5.18.0) with Mac OS 10.10, the selection of different file types for selecting a file is not enabled. Here is a snippet of code:

if demfile == None:
self.file_opt = options = {}
options['filetypes'] = [('All files', '*'),('ASCII files', '*.asc')]
options['initialdir'] = scoops.DefaultDir
fname = tkFileDialog.Open(**self.file_opt).show()

else:
fname = demfile

When opening a file in older versions of TCL, the Open window created would have a dropdown menu on the bottom with the option to select different file types. The dropdown choices are titled 'Enable'. In the more recent versions of TCL, this dropdown does not appear and the user is only allowed to select 'ASCII files'.
Any suggestions?
Thanks.
Dianne

grahams
ActiveState Staff
Tue, 2016-07-26 11:48

A number of commands have changed in the Tkinter API to support Tcl/Tk 8.5
https://docs.python.org/3.4/library/tkinter.html#tkinter-modules

tkFileDialog is one of them:
http://tkinter.unpythonic.net/wiki/tkFileDialog

New syntax should look more like this example:
from tkinter import filedialog
filename = filedialog.askopenfilename()
filename = filedialog.asksaveasfilename()
dirname = filedialog.askdirectory()

From Tkdocs
http://www.tkdocs.com/tutorial/windows.html
Standard Dialogs | Selecting Files and Directories.

Also, Tkinter will not use any Tcl 8.6 yet. It can only use a correctly installed 8.5. Tcl versions are defined according to the standards set by Python.org for the specific release when the module is compiled and can't be re-set.