Fix this error Exception in Tkinter callback Traceback (most recent call last): File…
- User
Fix this error Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\picky\AppData\Local\Programs\Python\Python310\lib\tkinter_init_.py", line 1921, in call return self.func(*args) File "D:\cookie monster\name.py", line 53, in select_source_folders folders = filedialog.askdirectory(mustexist=True, title="Select Source Folders", multiple=True) File "C:\Users\picky\AppData\Local\Programs\Python\Python310\lib\tkinter\filedialog.py", line 442, in askdirectory return Directory(**options).show() File "C:\Users\picky\AppData\Local\Programs\Python\Python310\lib\tkinter\commondialog.py", line 45, in show s = master.tk.call(self.command, *master._options(self.options)) _tkinter.TclError: bad option "-multiple": must be -initialdir, -mustexist, -parent, or -title. and then make the code based on this so that dfl image metadata stays use this @echo off
:: Code change to Unicode chcp 65001
rem Switch to the directory where the current batch file is located cd /d "%~dp0" REM dir
:: Create a localized environment setlocal enabledelayedexpansion
echo Please enter the option: 1. Add characters before the current folder picture, for example 00123.jpg change into a00123.jpg echo 2,All files in the current folder are reset sequentially to 00000.jpg - 99999.jpg
:MY_BEGIN
set /P StrInput="Enter the number:"
IF "%StrInput%" equ "1" (
echo To add characters before the current folder picture, please enter the character prefix to be added, for example, a, b, c. This is conducive to non-renaming and reordering set /P StrChar="Enter the prefix character:" for /f "delims=" %%F in ('dir /b *.jpg *.png') do ( REM echo Current file name:%%F REM echo rename "%%F" "!StrChar!%%F" rename "%%F" "!StrChar!%%F" REM echo rename "%%~dpnxF" "%%~dpF!StrChar!%%~nxF" )) ^ else IF "%StrInput%" equ "2" ( REM echo All files in the current folder are reset in order.
set count=-1 for /f "delims=" %%F in ('dir /b *.jpg *.png') do ( REM echo Current file name:%%F set /a count+=1 set "newfilename=00000!count!" set "newfilename=!newfilename:~-5!" set "newfilename=!newfilename!.jpg" rename "%%F" "!newfilename!" )) ^ else (
echo. echo Input error, please start over to input numbers 1 and 2, or tap X to close: goto MY_BEGIN
)
endlocal
echo wangle! pause and here is code import os import shutil from tkinter import ( Tk, Button, Label, Listbox, END, MULTIPLE, filedialog, messagebox, StringVar, ) from tkinter.ttk import Progressbar
class ImageCombinerGUI: def init(self, root): self.root = root self.root.title("Image Sequence Combiner")
self.source_folders = [] self.destination_folder = "" # Source Folders Selection self.btn_select_sources = Button( root, text="Select Source Folders", command=self.select_source_folders ) self.btn_select_sources.pack(pady=5) self.lbl_sources = Label(root, text="No source folders selected.") self.lbl_sources.pack() # Destination Folder Selection self.btn_select_destination = Button( root, text="Select Destination Folder", command=self.select_destination_folder ) self.btn_select_destination.pack(pady=5) self.lbl_destination = Label(root, text="No destination folder selected.") self.lbl_destination.pack() # Start Button self.btn_start = Button( root, text="Combine Images", command=self.combine_images ) self.btn_start.pack(pady=20) # Progress Bar self.progress = Progressbar(root, orient="horizontal", length=400, mode="determinate") self.progress.pack(pady=10) def select_source_folders(self): folders = filedialog.askdirectory(mustexist=True, title="Select Source Folders", multiple=True) if folders: # On some OS, folders might come as a tuple, ensure it's a list if isinstance(folders, str): folders = [folders] self.source_folders = list(folders) self.lbl_sources.config(text=f"Selected {len(self.source_folders)} source folder(s).") def select_destination_folder(self): folder = filedialog.askdirectory(mustexist=True, title="Select Destination Folder") if folder: self.destination_folder = folder self.lbl_destination.config(text=f"Destination: {self.destination_folder}") def combine_images(self): if not self.source_folders: messagebox.showwarning("No Source Folders", "Please select source folders first.") return if not self.destination_folder: messagebox.showwarning("No Destination Folder", "Please select a destination folder.") return total_files = 0 file_operations = [] # Gather all image files with their new prefixed names for src_folder in self.source_folders: main_prefix = os.path.basename(src_folder) for subdir, _, files in os.walk(src_folder): sub_prefix = os.path.basename(subdir) for file in files: if self.is_image_file(file): total_files += 1 new_prefix = f"{main_prefix}_{sub_prefix}" new_filename = f"{new_prefix}_{file}" src_file = os.path.join(subdir, file) dest_file = os.path.join(self.destination_folder, new_filename) file_operations.append((src_file, dest_file)) if total_files == 0: messagebox.showinfo("No Images Found", "No image files were found in the selected source folders.") return # Initialize progress bar self.progress["maximum"] = total_files self.progress["value"] = 0 # Copy files for idx, (src, dest) in enumerate(file_operations, start=1): try: shutil.copy2(src, dest) except Exception as e: messagebox.showerror("Error", f"Failed to copy {src} to {dest}.\n\nError: {e}") return self.progress["value"] = idx self.root.update_idletasks() messagebox.showinfo("Success", f"Successfully combined {total_files} images into {self.destination_folder}.") @staticmethod def is_image_file(filename): image_extensions = ('.png', '.jpg', '.jpeg', '.bmp', '.gif', '.tiff', '.webp') return filename.lower().endswith(image_extensions) - Assistant