“tkinter TclError:错误的文件类型"使用 askopenfilename

编程入门 行业动态 更新时间:2024-10-25 18:35:37
本文介绍了“tkinter TclError:错误的文件类型"使用 askopenfilename的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-30 08:05:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1391418.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件类型   错误   TclError   tkinter   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!