为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

撒科打诨 2022-11-09 16:59:41
我一直在调试一个程序,该程序从用户指定的目录获取文件,转换它们,并在另一个用户指定的目录中创建一个新文件。我现在收到一个我似乎无法弄清楚的错误。该start_command函数directory从e1输入框中获取 。我的browse功能可以完美地获取目录路径并将其放置在e1. 我self.directory.get()用来抓取路径并将其发送到start_command(). 我看不到我在这里遗漏了什么。任何见解都会有所帮助。错误:Exception in Tkinter callbackTraceback (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'
查看完整描述

1 回答

?
心有法竹

TA贡献1866条经验 获得超5个赞

使用此代码:


class PageOne(tk.Frame):


    def __init__(self, parent, controller):

        self.controller = controller

        tk.Frame.__init__(self, parent)


        l2 = Label(text='Use the browse buttons to select the proper folder.')

        l2.pack(side=TOP)

        l3 = Label(text='PDF Directory: The location of the folder containing the PDFs you wish to convert')

        l3.pack(side=TOP)

        l4 = Label(text='Excel Directory: The location you wish to create the Excel file within')

        l4.pack(side=TOP)

        instructions1 = Label(self, text='PDF Directory: ')

        instructions1.pack()

        self.directory = StringVar()

        e1 = Entry(self, textvariable=self.directory)

        e1.pack()

        b3 = Button(self, text='Browse', width=8, command=lambda: browsepath())

        b3.pack()

        instructions2 = Label(self, text='Excel Directory: ')

        instructions2.pack()

        self.excel_file = StringVar()

        e2 = Entry(self, textvariable=self.excel_file)

        e2.pack()

        b4 = Button(self, text='Browse', width=8, command=lambda: browsespd())

        b4.pack()


        progress = Progressbar(self, orient=HORIZONTAL, length=500, mode='determinate')

        progress.pack(side=BOTTOM)


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

        b1.pack(side=LEFT)

        b2 = Button(self, text='Close', width=12, command=quit)

        b2.pack(side=RIGHT)





    def start_command(self, excel_file, directory):

        converter.create_json(directory)

        converter.create_xlsx(excel_file, directory)

        converter.check_if_existing(directory)

        converter.convert(new_list, directory)



    def browsepath(self):

        foldername = filedialog.askdirectory()

        e1.delete(0, END)

        e1.insert(END, foldername)



    def browsespd(self):

        filename = filedialog.askdirectory()

        e2.delete(0, END)

        e2.insert(END, filename)

通过进一步的调整,如果没有Progressbar和convertor.


我所做的是 Ive madestart_command和browsepathlocal browsespdmethods ofPageOne通过使它们不同,这意味着您不需要传递它们的self参数,但是您现在必须使用类似self.start_commandor的东西来调用它们pageOne_object.start_command。


希望这会有所帮助!


查看完整回答
反对 回复 2022-11-09
  • 1 回答
  • 0 关注
  • 69 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信