main.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. """
  4. @Contact : liuyuqi.gov@msn.cn
  5. @Time : 2024/07/03
  6. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  7. @Desc :
  8. """
  9. import tkinter as tk
  10. from tkinter import ttk
  11. import pyperclip
  12. def update_listbox():
  13. '''
  14. 检查剪贴板,如果发现新内容,则将其添加到列表并更新 Tkinter 的 listbox。
  15. '''
  16. new_item = pyperclip.paste()
  17. if new_item not in X:
  18. X.append(new_item)
  19. listbox.insert(tk.END, new_item)
  20. listbox.insert(tk.END, "----------------------")
  21. listbox.yview(tk.END)
  22. def copy_to_clipboard(event):
  23. selected_item = listbox.get(listbox.curselection())
  24. if selected_item:
  25. pyperclip.copy(selected_item)
  26. X = []
  27. root = tk.Tk()
  28. root.title("Clipboard Manager")
  29. root.geometry("500x500")
  30. root.configure(bg="#f0f0f0")
  31. frame = tk.Frame(root, bg="#f0f0f0")
  32. frame.pack(padx=10, pady=10)
  33. label = tk.Label(frame, text="Clipboard Contents:", bg="#f0f0f0")
  34. label.grid(row=0, column=0)
  35. scrollbar = tk.Scrollbar(root)
  36. scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
  37. listbox = tk.Listbox(root, width=150, height=150, yscrollcommand=scrollbar.set)
  38. listbox.pack(pady=10)
  39. scrollbar.config(command=listbox.yview)
  40. update_listbox()
  41. # 每1秒执行一次
  42. root.after(1000, update_listbox)
  43. # 鼠标左键双击事件绑定到 copy_to_clipboard 函数
  44. listbox.bind("<Double-Button-1>", copy_to_clipboard)
  45. root.mainloop()
  46. if __name__=='__main__':
  47. pass