Can't make button know what file

Viewed 28

Can´t figure out how make my button know what file to execute the command on. So it makes a button with the right name. but then I want that button to execute the command on the file with that name.

#command for the button that gets made
def convert():
    pdffileobj=open()
    pdfreader=PyPDF2.PdfFileReader(pdffileobj)
    x=pdfreader.numPages
    pageobj=pdfreader.getPage(x+1)
    text=pageobj.extractText()

# folder path
dir_path = r'C:\Users\robin\Documents\Plocklistor'
# list of files
def lof():
    ext = ('pdf')
    for files in os.listdir(dir_path):
        if files.endswith(ext):
            for file in files:
                my_button = tk.Button(frame, text=files, padx=50, pady=5, fg="black", bg="#FFFFFF",command=convert,)
            my_button.pack()

#Button UPDATE LIST
PrintPPG = tk.Button(root, text="UPDATE LIST", padx=10, pady=5,
                          fg="white", bg="#8C00E6",command=lof)
PrintPPG.pack()
0 Answers
Related