diff --git a/file-explorer/file-explorer.py b/file-explorer/file-explorer.py index 0f5cf6b..7b05451 100644 --- a/file-explorer/file-explorer.py +++ b/file-explorer/file-explorer.py @@ -1,37 +1,63 @@ import tkinter as tk -from tkinter import filedialog - -def browse_file(): - file_path = filedialog.askopenfilename() - if file_path: - selected_file.set(file_path) - -def browse_directory(): - directory_path = filedialog.askdirectory() - if directory_path: - selected_directory.set(directory_path) - -# Create the main window -root = tk.Tk() -root.title("Cool File Explorer") - -# Create a label to display the selected file -selected_file = tk.StringVar() -file_label = tk.Label(root, textvariable=selected_file, font=('Helvetica', 12)) -file_label.pack(pady=10) - -# Create a button to browse for a file -file_button = tk.Button(root, text="Browse File", font=('Helvetica', 12), command=browse_file) -file_button.pack() - -# Create a label to display the selected directory -selected_directory = tk.StringVar() -directory_label = tk.Label(root, textvariable=selected_directory, font=('Helvetica', 12)) -directory_label.pack(pady=10) - -# Create a button to browse for a directory -directory_button = tk.Button(root, text="Browse Directory", font=('Helvetica', 12), command=browse_directory) -directory_button.pack() - -# Start the GUI main loop -root.mainloop() +from tkinter import filedialog, ttk + +class FileExplorerApp: + def __init__(self, root): + self.root = root + self.root.title("Enhanced File Explorer") + self.root.geometry("500x300") + self.root.resizable(True, True) + + # Configure styles + self.style = ttk.Style() + self.style.configure('TButton', font=('Helvetica', 12), padding=10) + self.style.configure('TLabel', font=('Helvetica', 12), padding=10) + + # Variables + self.selected_file = tk.StringVar() + self.selected_directory = tk.StringVar() + + self.setup_ui() + + def setup_ui(self): + # Main container frame + main_frame = ttk.Frame(self.root, padding="20") + main_frame.pack(fill=tk.BOTH, expand=True) + + # File selection section + file_frame = ttk.LabelFrame(main_frame, text="File Selection", padding=10) + file_frame.pack(fill=tk.X, pady=5) + + ttk.Button(file_frame, text="Browse File", command=self.browse_file).pack(side=tk.LEFT) + ttk.Label(file_frame, textvariable=self.selected_file, wraplength=400).pack(side=tk.LEFT, padx=10, fill=tk.X, expand=True) + + # Directory selection section + dir_frame = ttk.LabelFrame(main_frame, text="Directory Selection", padding=10) + dir_frame.pack(fill=tk.X, pady=5) + + ttk.Button(dir_frame, text="Browse Directory", command=self.browse_directory).pack(side=tk.LEFT) + ttk.Label(dir_frame, textvariable=self.selected_directory, wraplength=400).pack(side=tk.LEFT, padx=10, fill=tk.X, expand=True) + + # Status bar + self.status_bar = ttk.Label(main_frame, text="Ready", relief=tk.SUNKEN) + self.status_bar.pack(fill=tk.X, pady=(10, 0)) + + def browse_file(self): + file_path = filedialog.askopenfilename() + if file_path: + self.selected_file.set(file_path) + self.status_bar.config(text=f"Selected file: {file_path}") + + def browse_directory(self): + directory_path = filedialog.askdirectory() + if directory_path: + self.selected_directory.set(directory_path) + self.status_bar.config(text=f"Selected directory: {directory_path}") + +def main(): + root = tk.Tk() + app = FileExplorerApp(root) + root.mainloop() + +if __name__ == "__main__": + main()