有人能解释一下tkinters文件对话框是如何工作的吗?

2024-09-28 22:39:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我最近接受了朋友的挑战,但是我需要导入一个.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:\Users\jakeb\AppData\Local\Programs\Python\Python35-32\lib\tkinter\filedialog.py", line 375, in askopenfilename
    return Open(**options).show()
  File "C:\Users\jakeb\AppData\Local\Programs\Python\Python35-32\lib\tkinter\commondialog.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 ...?}?"
>>> 

p.s.麦克的回答没有用


Tags: 代码infrompyimporttkinter错误line
1条回答
网友
1楼 · 发布于 2024-09-28 22:39:53

更改此项:

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

对此:

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

文件类型需要作为类型列表提供。所以只要加上方括号。你知道吗

相关问题 更多 >