Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"tkinter TclError: bad file type" using askopenfilename

Tags:

This is my first time using Tkinter. I've imported it and it has been working up until this point. There's seems to be something wrong with the file type? I'm on a Mac as well if that makes any difference.

Here's my code:

def importTracks(self):
    self.fname = askopenfilename(filetypes=(("Mp3 Files", "*.mp3")))

Here's the error I'm receiving,

/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 /Users/accudeveloper/PycharmProjects/AccuAdmin2.0/AccuAdmin2.0.py
Exception in Tkinter callback
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tkinter/__init__.py", line 1533, in __call__
    return self.func(*args)
  File "/Users/accudeveloper/PycharmProjects/AccuAdmin2.0/AccuAdmin2.0.py", line 68, in importTracks
    self.fname = askopenfilename(filetypes=(("Mp3 Files", "*.mp3")))
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tkinter/filedialog.py", line 375, in askopenfilename
    return Open(**options).show()
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tkinter/commondialog.py", line 48, in show
    s = w.tk.call(self.command, *w._options(self.options))
_tkinter.TclError: bad file type "*.mp3", should be "typeName {extension ?extensions ...?} ?{macType ?macTypes ...?}?
like image 770
terratunaz Avatar asked Jul 30 '15 19:07

terratunaz


1 Answers

filetypes=(("Mp3 Files", "*.mp3")) is equivalent to filetypes=("Mp3 Files", "*.mp3"). I'm guessing you intended for the outer parentheses pair to be a tuple, but that requires a trailing comma. Or you can just use a list.

self.fname = askopenfilename(filetypes=(("Mp3 Files", "*.mp3"),))

Or

self.fname = askopenfilename(filetypes=[("Mp3 Files", "*.mp3")])
like image 165
Kevin Avatar answered Sep 21 '22 13:09

Kevin