Я отлаживал программу, которая получает файлы из указанного пользователем каталога, конвертирует их и создает новый файл в другом указанном пользователем каталоге. Я получаю сообщение об ошибке, которое не могу понять. Функция 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'
Код:
from tkinter import *
import tkinter as tk
import hashlib
import converter
import time
from tkinter.ttk import *
from tkinter import filedialog
class ITED(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
container.pack(side="top", fill="both", expand = True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F,geometry in zip((StartPage, PageOne), ('250x100', '550x250')):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = (frame, geometry)
frame.grid(row=0, column=0, sticky="nsew")
print(self.frames)
self.show_frame("StartPage")
def show_frame(self, page_name):
frame, geometry = self.frames[page_name]
self.update_idletasks()
self.geometry(geometry)
frame.tkraise()
def quit(self):
self.app.destroy()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
self.controller = controller
tk.Frame.__init__(self,parent)
l1 = Label(self, text='Please enter key:')
l1.pack(side=TOP, expand=True)
self.password = StringVar()
e3 = Entry(self, textvariable=self.password)
e3.pack(side=TOP, expand=True)
b6 = Button(self, text='Validate', width=12, command=lambda: self.admin(self.password.get()))
b6.pack(side=LEFT, expand=True)
b7 = Button(self, text='Close', width=12, command=quit)
b7.pack(side=LEFT, expand=True)
def admin(self, password):
admin_key = '72b302bf297a228a75730123efef7c41'
hash_object = hashlib.md5(password.encode())
key = hash_object.hexdigest()
if key == admin_key:
print('Success...')
self.destroy()
self.controller.show_frame("PageOne")
else:
print('Permission Denied...')
print(key)
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():
foldername = filedialog.askdirectory()
e1.delete(0, END)
e1.insert(END, foldername)
def browsespd():
filename = filedialog.askdirectory()
e2.delete(0, END)
e2.insert(END, filename)
def bar():
progress['value'] = 20
self.update_idletasks()
time.sleep(1)
progress['value'] = 40
self.update_idletasks()
time.sleep(1)
progress['value'] = 50
self.update_idletasks()
time.sleep(1)
progress['value'] = 60
self.update_idletasks()
time.sleep(1)
progress['value'] = 80
self.update_idletasks()
time.sleep(1)
progress['value'] = 100
if __name__ == "__main__":
app = ITED()
app.title("I.T.E.D. Converter")
app.mainloop()