askopenfile() 在 python 中获得参数 'mode' 的多个值
askopenfile() got multiple values for argument 'mode' in python
我正在 python 中编写一个 python 程序,它要求我使用打开的对话框
但我收到以下错误
askopenfile() 得到参数 'mode'
的多个值
我的代码
def open_file():
browse_text.set("loading...")
file = askopenfile(root, mode='r', title="Choose a file", filetype=[("pdf file", "*.pdf")])
if file:
read_file = PyPDF2.PdfFileReader(file)
page = read_file.getPage(0)
page_content = page.extractText()
text_box = tk.Tex(root, height=10, width=50, padx=15, pady=15)
text_box.insert(1.0, page_content)
text_box.grid(column=1, row=3)
browse_text = tk.StringVar();
browse_btn = tk.Button(root, textvariable=browse_text, command=lambda: open_file(), bg="blue", fg="white", font="arial", height=3, width=15)
browse_text.set("Open file")
askopenfile
does not accept a root
parameter.
>>> from tkinter.filedialog import askopenfile
>>> help(askopenfile)
Help on function askopenfile in module tkinter.filedialog:
askopenfile(mode='r', **options)
Ask for a filename to open, and returned the opened file
所以改变一下
file = askopenfile(root, mode='r', title="Choose a file", filetype=[("pdf file", "*.pdf")])
至
file = askopenfile(mode='r', title="Choose a file", filetype=[("pdf file", "*.pdf")])
我正在 python 中编写一个 python 程序,它要求我使用打开的对话框
但我收到以下错误
askopenfile() 得到参数 'mode'
的多个值我的代码
def open_file():
browse_text.set("loading...")
file = askopenfile(root, mode='r', title="Choose a file", filetype=[("pdf file", "*.pdf")])
if file:
read_file = PyPDF2.PdfFileReader(file)
page = read_file.getPage(0)
page_content = page.extractText()
text_box = tk.Tex(root, height=10, width=50, padx=15, pady=15)
text_box.insert(1.0, page_content)
text_box.grid(column=1, row=3)
browse_text = tk.StringVar();
browse_btn = tk.Button(root, textvariable=browse_text, command=lambda: open_file(), bg="blue", fg="white", font="arial", height=3, width=15)
browse_text.set("Open file")
askopenfile
does not accept a root
parameter.
>>> from tkinter.filedialog import askopenfile
>>> help(askopenfile)
Help on function askopenfile in module tkinter.filedialog:
askopenfile(mode='r', **options)
Ask for a filename to open, and returned the opened file
所以改变一下
file = askopenfile(root, mode='r', title="Choose a file", filetype=[("pdf file", "*.pdf")])
至
file = askopenfile(mode='r', title="Choose a file", filetype=[("pdf file", "*.pdf")])