From 52618ac3d6beb0a4dc4ada14dc8f2df3dee42c5a Mon Sep 17 00:00:00 2001 From: captainAyan Date: Tue, 8 Oct 2024 00:23:17 +0530 Subject: [PATCH] added multi-file selection --- main.py | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 42e92e9..4dae7be 100644 --- a/main.py +++ b/main.py @@ -15,20 +15,34 @@ def modify_image_with_random_data(file_path): def submit(): - """Handle the submit button click.""" - file_path = file_entry.get() - if os.path.isfile(file_path): - modify_image_with_random_data(file_path) - messagebox.showinfo("Success", f"Corrupted {file_path} with random data.") + total_files = listbox.size() + if total_files != 0: + for index in range(total_files): + file_path = listbox.get(index) # Get the file path from the Listbox + + if os.path.isfile(file_path): + modify_image_with_random_data(file_path) # Call your function to modify the image + else: + messagebox.showerror("Error", f"File not found: {file_path}") + messagebox.showinfo("Success", "Corrupted files with random data.") else: - messagebox.showerror("Error", "File not found!") + messagebox.showerror("Error", "No files selected!") def browse_file(): """Open file dialog to select a file.""" - filename = filedialog.askopenfilename(filetypes=[("PNG Files", "*.png"), ("All Files", "*.*")]) - file_entry.delete(0, tk.END) # Clear the entry - file_entry.insert(0, filename) # Insert the selected file path + filenames = filedialog.askopenfilenames(filetypes=[("All Files", "*.*")]) + + listbox.delete(0, tk.END) + + if filenames: + for filename in filenames: + listbox.insert(tk.END, filename) # Insert each selected file into the Listbox + + message_label.config(text=f"{listbox.size()} {'file' if listbox.size()==1 else 'files'} selected") + else: + message_label.config(text="Select a file to corrupt:") + # mongo smoothie theme @@ -46,7 +60,7 @@ def browse_file(): # Create the main window root = tk.Tk() root.title("Corruptinator") -root.geometry("400x320") # Set a fixed size for the window +root.geometry("400x360") # Set a fixed size for the window root.configure(bg=bg_color) # Set background color root.resizable(False, False) @@ -58,17 +72,17 @@ def browse_file(): frame = tk.Frame(root, bg=bg_color) frame.pack(padx=20, pady=0) -tk.Label(frame, text="Select a file to corrupt:", bg=bg_color, font=("Arial", 12), fg=text_color).pack(pady=10) - -file_entry = tk.Entry(frame, width=400, font=("Arial", 12), bd=2, relief="groove") -file_entry.pack(pady=10) +message_label = tk.Label(frame, text="Select a file to corrupt:", bg=bg_color, font=("Arial Black", 10), fg=text_color) +message_label.pack(pady=10) +listbox = tk.Listbox(frame, width=400, height=5) # You can adjust the width and height as needed +listbox.pack(pady=2) browse_button = tk.Button(frame, text="Browse", command=browse_file, bg=browse_btn_color, fg="white", font=("Arial Black", 12), bd=0, width=400) -browse_button.pack(pady=5) +browse_button.pack(pady=2) submit_button = tk.Button(frame, text="Corrupt", command=submit, bg=submit_btn_color, fg="white", font=("Arial Black", 12), bd=0, width=400) -submit_button.pack(pady=5) +submit_button.pack(pady=2) github_link = "GitHub @captainayan" github_label = tk.Label(root, text=github_link, bg=bg_color, font=("Arial", 10), fg="#007BFF")