问题描述
限时送ChatGPT账号..这是我第一次使用 Tkinter.我已经导入了它,直到现在它一直在工作.文件类型似乎有问题?如果这有什么不同,我也在 Mac 上.
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.
这是我的代码:
def importTracks(self):
self.fname = askopenfilename(filetypes=(("Mp3 Files", "*.mp3")))
这是我收到的错误,
/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(selfmand, *w._options(self.options))
_tkinter.TclError: bad file type "*.mp3", should be "typeName {extension ?extensions ...?} ?{macType ?macTypes ...?}?
推荐答案
filetypes=(("Mp3 Files", "*.mp3"))
等价于 filetypes=("Mp3 文件"、*.mp3")
.我猜你打算让外括号对成为一个元组,但这需要一个尾随逗号.或者你可以只使用一个列表.
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"),))
或
self.fname = askopenfilename(filetypes=[("Mp3 Files", "*.mp3")])
这篇关于“tkinter TclError:错误的文件类型"使用 askopenfilename的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论