22

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 ...?}?
nbro
  • 15,395
  • 32
  • 113
  • 196
terratunaz
  • 614
  • 3
  • 9
  • 19

1 Answers1

45

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")])
Kevin
  • 74,910
  • 12
  • 133
  • 166
  • 1
    Thanks so much Kevin! I kid you not, I realized this about a minute before you posted. Guess I should have just played around with it a bit more before crying for help. :) – terratunaz Jul 30 '15 at 19:20