请有人解释一下tkinters文件对话框的工作原理吗?



我最近接受了朋友的挑战,但是我需要导入一个.dll才能做到这一点。 为此,我想出了以下代码:

from tkinter import *
from tkinter.filedialog import askopenfilename
import ctypes
dll = ctypes.WinDLL(askopenfilename(filetypes=("All files", "*.*")))

但是这似乎会产生错误,并且我实际上还没有打开文件对话框。请有人帮助我修复我的代码或解释为什么会出错。

编辑:

错误是:

Traceback (most recent call last):
File "C:/Users/jakeb/Desktop/New folder/jakes exploit.py", line 6, in <module>
exploitapi = ctypes.WinDLL(askopenfilename(filetypes=("All files", "*.*")))
File "C:UsersjakebAppDataLocalProgramsPythonPython35-32libtkinterfiledialog.py", line 375, in askopenfilename
return Open(**options).show()
File "C:UsersjakebAppDataLocalProgramsPythonPython35-32libtkintercommondialog.py", line 48, in show
s = w.tk.call(self.command, *w._options(self.options))
_tkinter.TclError: bad file type "*.*", should be "typeName {extension ?extensions ...?} ?{macType ?macTypes ...?}?"
>>> 

附言迈克斯的答案没有用

更改以下内容:

dll = ctypes.WinDLL(askopenfilename(filetypes=("All files", "*.*")))

对此:

dll = ctypes.WinDLL(askopenfilename(filetypes=[("All files","*.*")]))

文件类型需要作为类型列表提供。因此,只需添加方括号即可。

最新更新