#!/usr/bin/env python # -*- encoding: utf-8 -*- """ @Contact : liuyuqi.gov@msn.cn @Time : 2024/07/03 @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved. @Desc : """ import tkinter as tk from tkinter import ttk import pyperclip def update_listbox(): ''' 检查剪贴板,如果发现新内容,则将其添加到列表并更新 Tkinter 的 listbox。 ''' new_item = pyperclip.paste() if new_item not in X: X.append(new_item) listbox.insert(tk.END, new_item) listbox.insert(tk.END, "----------------------") listbox.yview(tk.END) def copy_to_clipboard(event): selected_item = listbox.get(listbox.curselection()) if selected_item: pyperclip.copy(selected_item) X = [] root = tk.Tk() root.title("Clipboard Manager") root.geometry("500x500") root.configure(bg="#f0f0f0") frame = tk.Frame(root, bg="#f0f0f0") frame.pack(padx=10, pady=10) label = tk.Label(frame, text="Clipboard Contents:", bg="#f0f0f0") label.grid(row=0, column=0) scrollbar = tk.Scrollbar(root) scrollbar.pack(side=tk.RIGHT, fill=tk.Y) listbox = tk.Listbox(root, width=150, height=150, yscrollcommand=scrollbar.set) listbox.pack(pady=10) scrollbar.config(command=listbox.yview) update_listbox() # 每1秒执行一次 root.after(1000, update_listbox) # 鼠标左键双击事件绑定到 copy_to_clipboard 函数 listbox.bind("", copy_to_clipboard) root.mainloop() if __name__=='__main__': pass