Tkinter設置askopenfilename通過filetypes指定只能打開某一種格式的文件時,不能打開文件選擇器。
比如我這里指定只能打開pdf文件
代碼
inputPath=askopenfilename(title="Select PDF file", filetypes=(("pdf files", "*.pdf")))
但點擊了按鈕后並沒有反應,報錯信息顯示 tkinter.TclError: bad file type...
具體報錯信息如下:
_tkinter.TclError: bad file type "*.pdf", should be "typeName {extension ?extensions ...?} ?{macType ?macTypes ...?}?"
這里出現錯誤的原因時缺少了一個逗號 ,
要在 ("pdf files", "*.pdf") 后面加個英文的逗號(不知道作為分隔符還是結束標志)
inputPath=askopenfilename(title="Select PDF file", filetypes=(("pdf files", "*.pdf"),))
就好了
講真這設定有點智障