Closed StuartJAtkinson closed 2 days ago
To implement a GUI interface for batch processing files or folders, we can use the Tkinter library in Python. The GUI will allow users to drag and drop or browse for files or folders, and then display the file names, their extension types, and paths in a new window. This approach ensures a user-friendly interface for batch processing.
Here is the complete implementation for gui_interface.py
:
import tkinter as tk
from tkinter import filedialog, messagebox
import os
class GUIInterface:
def __init__(self, root):
self.root = root
self.root.title("Batch File Processor")
# Create a menu bar
menubar = tk.Menu(root)
filemenu = tk.Menu(menubar, tearoff=0)
filemenu.add_command(label="Open Files", command=self.open_files)
filemenu.add_command(label="Open Folder", command=self.open_folder)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="File", menu=filemenu)
root.config(menu=menubar)
def open_files(self):
file_paths = filedialog.askopenfilenames(title="Select Files")
if file_paths:
self.display_file_info(file_paths)
def open_folder(self):
folder_path = filedialog.askdirectory(title="Select Folder")
if folder_path:
file_paths = [os.path.join(folder_path, f) for f in os.listdir(folder_path)]
self.display_file_info(file_paths)
def display_file_info(self, file_paths):
info_window = tk.Toplevel(self.root)
info_window.title("File Information")
text = tk.Text(info_window, wrap='word')
text.pack(expand=1, fill='both')
for file_path in file_paths:
if os.path.isfile(file_path):
file_name = os.path.basename(file_path)
file_ext = os.path.splitext(file_name)[1]
text.insert(tk.END, f"Name: {file_name}, Extension: {file_ext}, Path: {file_path}\n")
else:
text.insert(tk.END, f"Path: {file_path} is not a file.\n")
text.config(state=tk.DISABLED)
if __name__ == "__main__":
root = tk.Tk()
app = GUIInterface(root)
root.mainloop()
tkinter
module is used for the GUI, and filedialog
for file/folder selection dialogs. The os
module is used to handle file paths.GUIInterface
class initializes the main window and sets up the menu bar.filemenu
contains commands to open files, open a folder, and exit the application.open_files
method uses filedialog.askopenfilenames
to allow multiple file selection. The open_folder
method uses filedialog.askdirectory
to select a folder and lists all files in it.display_file_info
method creates a new window and displays the file names, their extension types, and paths in a text widget.This implementation provides a basic GUI interface as requested. You can further enhance it by adding more features or improving the UI as needed.
Click here to create a Pull Request with the proposed solution
Files used for this task:
What A GUI interface for the drag and drop or browsing for files or folders to itterate through.
Why I want this to be a batch process rather than a singular one. So I need a simple starting point. To begin I would want a simple GUI window with a file menu item to open files or folders. Functionally I would want this to open another window which lists the file names, their extention type, and path.