The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Build a minimalist file explorer with Python

Building a minimalist file explorer with Python involves creating a simple graphical user interface (GUI) to navigate the filesystem. Here’s a working example using tkinter, which is included in Python’s standard library. This file explorer allows users to:

  • Navigate through directories

  • Open files with the default OS application

  • Go back to the parent directory

python
import os import tkinter as tk from tkinter import filedialog, messagebox import subprocess import platform class MinimalistFileExplorer: def __init__(self, root): self.root = root self.root.title("Minimalist File Explorer") self.current_path = os.path.expanduser("~") # Path label self.path_label = tk.Label(root, text=self.current_path, anchor='w', bg='white', relief='sunken') self.path_label.pack(fill=tk.X, padx=5, pady=5) # File list self.file_listbox = tk.Listbox(root, selectmode=tk.SINGLE) self.file_listbox.pack(fill=tk.BOTH, expand=True, padx=5, pady=5) self.file_listbox.bind('<Double-1>', self.open_selected) # Buttons btn_frame = tk.Frame(root) btn_frame.pack(fill=tk.X, padx=5, pady=5) tk.Button(btn_frame, text="Up", command=self.go_up).pack(side=tk.LEFT) tk.Button(btn_frame, text="Open", command=self.open_selected).pack(side=tk.LEFT) tk.Button(btn_frame, text="Refresh", command=self.load_directory).pack(side=tk.LEFT) self.load_directory() def load_directory(self): try: items = os.listdir(self.current_path) except PermissionError: messagebox.showerror("Permission Denied", f"Cannot access {self.current_path}") return self.file_listbox.delete(0, tk.END) self.path_label.config(text=self.current_path) # List directories first for item in sorted(items, key=lambda x: (not os.path.isdir(os.path.join(self.current_path, x)), x.lower())): self.file_listbox.insert(tk.END, item) def go_up(self): parent_dir = os.path.dirname(self.current_path) if os.path.exists(parent_dir): self.current_path = parent_dir self.load_directory() def open_selected(self, event=None): selected = self.file_listbox.curselection() if not selected: return selected_name = self.file_listbox.get(selected[0]) full_path = os.path.join(self.current_path, selected_name) if os.path.isdir(full_path): self.current_path = full_path self.load_directory() else: try: if platform.system() == "Windows": os.startfile(full_path) elif platform.system() == "Darwin": # macOS subprocess.call(["open", full_path]) else: # Linux subprocess.call(["xdg-open", full_path]) except Exception as e: messagebox.showerror("Error", f"Cannot open file: {e}") if __name__ == "__main__": root = tk.Tk() root.geometry("600x400") app = MinimalistFileExplorer(root) root.mainloop()

Key Features:

  • Uses tkinter for GUI

  • Starts in the user’s home directory

  • Double-click to open folders or launch files

  • Basic navigation (up one directory, refresh view)

To Run:
Save the code to a .py file and execute it with Python 3:

bash
python minimalist_file_explorer.py

No additional libraries are needed.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About