start_command() 缺少 1 个位置参数?

我一直在调试一个程序,该程序从用户指定的目录获取文件,转换它们,并在另一个用户指定的目录中创建一个新文件。我现在收到一个我似乎无法弄清楚的错误。该start_command函数directory从e1输入框中获取 。我的browse功能可以完美地获取目录路径并将其放置在e1. 我self.directory.get()用来抓取路径并将其发送到start_command(). 我看不到我在这里遗漏了什么。任何见解都会有所帮助。


错误:


Exception in Tkinter callback

Traceback (most recent call last):

  File "/usr/lib/python3.8/tkinter/__init__.py", line 1883, in __call__

    return self.func(*args)

  File "/root/Desktop/I.T.E.D./ITED.py", line 108, in <lambda>

    b1 = Button(self, text='Start', width=12, command=lambda: start_command(self.excel_file.get(), self.directory.get()))

TypeError: start_command() missing 1 required positional argument: 'directory'


撒科打诨
浏览 56回答 1
1回答

心有法竹

使用此代码:class PageOne(tk.Frame):&nbsp; &nbsp; def __init__(self, parent, controller):&nbsp; &nbsp; &nbsp; &nbsp; self.controller = controller&nbsp; &nbsp; &nbsp; &nbsp; tk.Frame.__init__(self, parent)&nbsp; &nbsp; &nbsp; &nbsp; l2 = Label(text='Use the browse buttons to select the proper folder.')&nbsp; &nbsp; &nbsp; &nbsp; l2.pack(side=TOP)&nbsp; &nbsp; &nbsp; &nbsp; l3 = Label(text='PDF Directory: The location of the folder containing the PDFs you wish to convert')&nbsp; &nbsp; &nbsp; &nbsp; l3.pack(side=TOP)&nbsp; &nbsp; &nbsp; &nbsp; l4 = Label(text='Excel Directory: The location you wish to create the Excel file within')&nbsp; &nbsp; &nbsp; &nbsp; l4.pack(side=TOP)&nbsp; &nbsp; &nbsp; &nbsp; instructions1 = Label(self, text='PDF Directory: ')&nbsp; &nbsp; &nbsp; &nbsp; instructions1.pack()&nbsp; &nbsp; &nbsp; &nbsp; self.directory = StringVar()&nbsp; &nbsp; &nbsp; &nbsp; e1 = Entry(self, textvariable=self.directory)&nbsp; &nbsp; &nbsp; &nbsp; e1.pack()&nbsp; &nbsp; &nbsp; &nbsp; b3 = Button(self, text='Browse', width=8, command=lambda: browsepath())&nbsp; &nbsp; &nbsp; &nbsp; b3.pack()&nbsp; &nbsp; &nbsp; &nbsp; instructions2 = Label(self, text='Excel Directory: ')&nbsp; &nbsp; &nbsp; &nbsp; instructions2.pack()&nbsp; &nbsp; &nbsp; &nbsp; self.excel_file = StringVar()&nbsp; &nbsp; &nbsp; &nbsp; e2 = Entry(self, textvariable=self.excel_file)&nbsp; &nbsp; &nbsp; &nbsp; e2.pack()&nbsp; &nbsp; &nbsp; &nbsp; b4 = Button(self, text='Browse', width=8, command=lambda: browsespd())&nbsp; &nbsp; &nbsp; &nbsp; b4.pack()&nbsp; &nbsp; &nbsp; &nbsp; progress = Progressbar(self, orient=HORIZONTAL, length=500, mode='determinate')&nbsp; &nbsp; &nbsp; &nbsp; progress.pack(side=BOTTOM)&nbsp; &nbsp; &nbsp; &nbsp; b1 = Button(self, text='Start', width=12, command=lambda: self.start_command(self.excel_file.get(), self.directory.get()))&nbsp; &nbsp; &nbsp; &nbsp; b1.pack(side=LEFT)&nbsp; &nbsp; &nbsp; &nbsp; b2 = Button(self, text='Close', width=12, command=quit)&nbsp; &nbsp; &nbsp; &nbsp; b2.pack(side=RIGHT)&nbsp; &nbsp; def start_command(self, excel_file, directory):&nbsp; &nbsp; &nbsp; &nbsp; converter.create_json(directory)&nbsp; &nbsp; &nbsp; &nbsp; converter.create_xlsx(excel_file, directory)&nbsp; &nbsp; &nbsp; &nbsp; converter.check_if_existing(directory)&nbsp; &nbsp; &nbsp; &nbsp; converter.convert(new_list, directory)&nbsp; &nbsp; def browsepath(self):&nbsp; &nbsp; &nbsp; &nbsp; foldername = filedialog.askdirectory()&nbsp; &nbsp; &nbsp; &nbsp; e1.delete(0, END)&nbsp; &nbsp; &nbsp; &nbsp; e1.insert(END, foldername)&nbsp; &nbsp; def browsespd(self):&nbsp; &nbsp; &nbsp; &nbsp; filename = filedialog.askdirectory()&nbsp; &nbsp; &nbsp; &nbsp; e2.delete(0, END)&nbsp; &nbsp; &nbsp; &nbsp; e2.insert(END, filename)通过进一步的调整,如果没有Progressbar和convertor.我所做的是 Ive madestart_command和browsepathlocal browsespdmethods ofPageOne通过使它们不同,这意味着您不需要传递它们的self参数,但是您现在必须使用类似self.start_commandor的东西来调用它们pageOne_object.start_command。希望这会有所帮助!
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python