Categories We Write About

Create a smart clipboard manager

Here’s a basic yet smart clipboard manager written in Python using tkinter for GUI and pyperclip for clipboard access. It stores copied text entries, allows search, and lets users re-copy or delete entries from the list.


Features:

  • Stores clipboard history automatically.

  • Avoids duplicates.

  • Search bar to filter clipboard history.

  • Re-copy to clipboard by clicking.

  • Delete selected entries.


⚙️ Requirements:

Install dependencies:

bash
pip install pyperclip

📜 Code: Smart Clipboard Manager

python
import tkinter as tk from tkinter import simpledialog, messagebox import pyperclip import threading import time class ClipboardManager: def __init__(self, root): self.root = root self.root.title("Smart Clipboard Manager") self.history = [] self.filtered_history = [] self.running = True # GUI Components self.search_var = tk.StringVar() self.search_var.trace("w", self.update_listbox) self.entry_search = tk.Entry(root, textvariable=self.search_var, width=50) self.entry_search.pack(padx=10, pady=5) self.listbox = tk.Listbox(root, width=60, height=20) self.listbox.pack(padx=10, pady=5) self.listbox.bind("<Double-1>", self.copy_selected) self.btn_frame = tk.Frame(root) self.btn_frame.pack(pady=5) self.btn_delete = tk.Button(self.btn_frame, text="Delete Selected", command=self.delete_selected) self.btn_delete.pack(side=tk.LEFT, padx=5) self.btn_clear = tk.Button(self.btn_frame, text="Clear All", command=self.clear_all) self.btn_clear.pack(side=tk.LEFT, padx=5) # Start monitoring clipboard self.last_clipboard = "" self.clipboard_thread = threading.Thread(target=self.monitor_clipboard, daemon=True) self.clipboard_thread.start() # Safe exit self.root.protocol("WM_DELETE_WINDOW", self.on_close) def monitor_clipboard(self): while self.running: try: current_clipboard = pyperclip.paste() if current_clipboard != self.last_clipboard and current_clipboard.strip(): self.last_clipboard = current_clipboard if current_clipboard not in self.history: self.history.insert(0, current_clipboard) self.update_listbox() except Exception as e: print(f"Error: {e}") time.sleep(1) def update_listbox(self, *args): search_text = self.search_var.get().lower() self.listbox.delete(0, tk.END) self.filtered_history = [text for text in self.history if search_text in text.lower()] for item in self.filtered_history: self.listbox.insert(tk.END, item) def copy_selected(self, event): try: selected = self.listbox.get(self.listbox.curselection()) pyperclip.copy(selected) except: pass def delete_selected(self): try: selected = self.listbox.get(self.listbox.curselection()) if selected in self.history: self.history.remove(selected) self.update_listbox() except: pass def clear_all(self): if messagebox.askyesno("Clear All", "Are you sure you want to clear the entire clipboard history?"): self.history.clear() self.update_listbox() def on_close(self): self.running = False self.root.destroy() if __name__ == "__main__": root = tk.Tk() app = ClipboardManager(root) root.mainloop()

🧠 Suggestions for Improvement:

  • Save history to disk (pickle or JSON).

  • Add hotkeys to quickly show or paste.

  • Integrate images and file path copying.

  • Use keyboard module for hotkey listening.

Let me know if you’d like an advanced version with persistent storage or cross-platform support.

Share This Page:

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

We respect your email privacy

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories We Write About