Tkinter and openpyxl error no such file or directory '' Tkinter and openpyxl error no such file or directory '' tkinter tkinter

Tkinter and openpyxl error no such file or directory ''


From what I can see of your code the problem is because you have not actually add the file names to the variables you are trying to use.

So when your program gets to the lines where workbook1, workbook2, worksheet1, and worksheet2 are the program is trying to run the command openpyxl.load_workbook(str(wb1)) before the variables wb1, wb2, wb1, sheet1, and sheet2 have been created. You need to have the functions that ask for the file name to assign to the variables to be called before you create the following:

workbook1 = openpyxl.load_workbook(str(wb1))workbook2 = openpyxl.load_workbook(str(wb2))worksheet1 = workbook1.get_sheet_by_name(str(sheet1))worksheet2 = workbook2.get_sheet_by_name(str(sheet2))

Here is an example of what you might want to do in order to accomplish this.

This is not the best way or even a good way but it will work for your needs in a hurry and give an example of what is needed for your workbooks and worksheets to be dealt with properly.

def ask_for_filename_1():    global wb1    wb1 = askopenfilename(title="Select Workbook 1")    print(str(wb1))    return wb1ask_for_filename_1() # add this linedef ask_for_filename_2():    global wb2    wb2 = askopenfilename(title="Select Workbook 1")    print(str(wb2))    return wb2ask_for_filename_2() # add this line

you will need to do this for ever function that applies a file name to a variable before you work with said variables.

Keep in mind the example I gave is just to illustrate what needs to happen before you do anything with the variables workbook1, workbook2, worksheet1, and worksheet2. You may want to review and change your code so this is not a problem in the future.

Maybe add this section:

workbook1 = openpyxl.load_workbook(str(wb1))workbook2 = openpyxl.load_workbook(str(wb2))worksheet1 = workbook1.get_sheet_by_name(str(sheet1))worksheet2 = workbook2.get_sheet_by_name(str(sheet2))

to a function that is called after each wb1, wb2, wb1, sheet1, and sheet2 have been created.