亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 100 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號