如何修复'fp.seek查找(自启动目录,0)OSError:[Errno 22]python中的参数“”无效

2024-09-29 19:29:53 发布

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

我正在编写一个python应用程序来解压存档文件,但遇到了一个错误。你知道吗

我尝试过重命名文件并删除脚本中不必要的部分。你知道吗

我的剧本是:


import zipfile
import tkinter as tk
import tkinter.ttk as ttk
import tkinter.messagebox as mgb
import tkinter.filedialog as tkfd

OutputPath = ""
ZIPFile = ""

root = tk.Tk()

def OpenFile() :
    global ZIPFile
    global OutputPath
    ZIPFile = tkfd.askopenfilename(initialdir = "/",title = "Select file")
    if OutputPath != "" and ZIPFile != "" : ZipBut.state(["!disabled"])


def OutputFile() :
    global OutputPath
    global ZIPFile
    OutputPath = tkfd.askdirectory(initialdir = "/", title = "Select file")
    if OutputPath != "" and ZIPFile != "" : ZipBut.state(["!disabled"])

def unzip() :
    global ZIPFile
    global OutputPath

    with zipfile.ZipFile(ZIPFile) as File :
        File.extractall(path = OutputPath)

CommandBar = ttk.Frame(root)
CommandBar.pack()

ttk.Button(CommandBar, text = "open", command = OpenFile).grid(row = 0, column = 0)
ttk.Button(CommandBar, text = "output", command = OutputFile).grid(row = 0, column = 1)
ZipBut = ttk.Button(CommandBar, text = "unzip", command = unzip)
ZipBut.grid(row = 0, column = 2)
ZipBut.state(["disabled"])

root.mainloop()

我希望该文件解压缩到一个文件夹的选择,但得到一个例外

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\dell\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 1558, in __call__
    return self.func(*args)
  File "C:/Users/dell/Desktop/ZIP/main.pyw", line 29, in unzip
    with zipfile.ZipFile(ZIPFile) as File :
  File "C:\Users\dell\AppData\Local\Programs\Python\Python35-32\lib\zipfile.py", line 1026, in __init__
    self._RealGetContents()
  File "C:\Users\dell\AppData\Local\Programs\Python\Python35-32\lib\zipfile.py", line 1111, in _RealGetContents
    fp.seek(self.start_dir, 0)
OSError: [Errno 22] Invalid argument

Tags: inimporttkinterasglobalusersdellfile

热门问题