Advertisement
here2share

# tk_multi_preset_clipboard.py

Dec 27th, 2022
1,474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.08 KB | None | 0 0
  1. # tk_multi_clipboard.py ZZZ
  2.  
  3. import tkinter as tk
  4.  
  5. root = tk.Tk()
  6. root.title("tk_multi_clipboard")
  7.  
  8. copied_texts = []
  9.  
  10. toplabel = tk.Label()
  11. toplabel.pack()
  12.  
  13. label2 = tk.Label()
  14. label2.pack()
  15.  
  16. auto_saved_label = tk.Label(toplabel, text="Auto-Saved Clipboard Contents (30 MAX):"+" "*112)
  17. auto_saved_label.pack(side='left', anchor='w')
  18.  
  19. clipboard_label = tk.Label(toplabel, text="Preset Clipboard Contents:")
  20. clipboard_label.pack(side='left', anchor='e')
  21.  
  22. clipboard_contents = tk.Listbox(label2, width=60, height=30)
  23. clipboard_contents.pack(side='left')
  24.  
  25. copied_texts_listbox = tk.Listbox(label2, width=60, height=30)
  26. copied_texts_listbox.pack(side='right')
  27.  
  28. copy_button = tk.Button(root, text="Copy To Preset", command=lambda: copy_to_list())
  29. copy_button.pack(side='left')
  30.  
  31. edit_button = tk.Button(root, text="Edit Preset", command=lambda: edit_text())
  32. edit_button.pack(side='right')
  33.  
  34. delete_button = tk.Button(root, text="Delete Preset", command=lambda: delete_text())
  35. delete_button.pack(side='right')
  36.  
  37. def copy_to_list():
  38.     clipboard_data = root.clipboard_get()
  39.  
  40.     if clipboard_data not in copied_texts:
  41.         copied_texts.append(clipboard_data)
  42.  
  43.     copied_texts_listbox.delete(0, tk.END)
  44.     for text in copied_texts:
  45.         copied_texts_listbox.insert(tk.END, text)
  46.  
  47.     del copied_texts[:-30]
  48.  
  49. def edit_text():
  50.     selection = copied_texts_listbox.curselection()
  51.     if selection:
  52.         selected_text = copied_texts_listbox.get(selection[0])
  53.  
  54.         clipboard_contents.delete("1.0", tk.END)
  55.         clipboard_contents.insert("1.0", selected_text)
  56.  
  57.         copied_texts.remove(selected_text)
  58.  
  59. def delete_text():
  60.     selection = copied_texts_listbox.curselection()
  61.     if selection:
  62.         selected_text = copied_texts_listbox.get(selection[0])
  63.  
  64.         copied_texts.remove(selected_text)
  65.  
  66.         copied_texts_listbox.delete(0, tk.END)
  67.         for text in copied_texts:
  68.             copied_texts_listbox.insert(tk.END, text)
  69.  
  70. root.mainloop()
  71.  
  72. '''
  73. root.clipboard_get()
  74.  
  75. root.clipboard_clear()
  76. root.clipboard_append("Hello World")
  77. '''
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement