Mar-06-2023, 02:55 PM
You created your temporary directory in the wrong place. You should have created the directory in the select_pdf_files() function.
def select_pdf_file(): global images, temp_folder # open file dialog to choose a PDF file if file_path := filedialog.askopenfilename(filetypes=[("PDF Files", "*.pdf")]): if file_path: temp_dir = tempfile.TemporaryDirectory() # <-- Create temporary directory here with fitz.open(file_path) as pdf_file: for page_index in range(len(pdf_file)):For the first PDF, this will work exactly like your program. The second time you open a PDF, re-assigning temp_dir deletes the previous temporary directiory and you have a new, empty, temporary directory to work with. After opening three PDF files the temporary directory would contain images from the last PDF file. The way your program was written, opening a PDF added files to the temporary directory. After opening three PDF files, the temporary directory would contain images from three different PDF files.