簡體   English   中英

如何使用python創建復制和粘貼程序

[英]how to create copy and paste program with python

如何使用 Python 編寫可以在 Windows 中充當復制和粘貼的程序? 我用python庫做了兩個按鈕,想在windows環境下做一個拷貝,在粘貼中做一個。 謝謝你幫助我。

這是我的代碼

import tkinter as tk
import pyautogui as pg
import time


root = tk.Tk()
root.geometry("200x160")
root.resizable(False, False)


is_checked = tk.IntVar()


def alont():
    if is_checked.get() == 0:
        root.attributes('-topmost', False)   
    else:
        root.attributes('-topmost', True)

text1 = tk.Entry(root, font = ("area", 10), width = 5)

text1.config(insertwidth=1)

text1.place(x=10, y=137)

text1.insert(0, 1)
timer1 = text1.get()

def copy1():

    timer1 = text1.get()
    tm = int(timer1)
    time.sleep(tm)
    pg.hotkey('ctrl', 'c')

def paste1():

    timer1 = text1.get()
    tm = int(timer1)
    time.sleep(tm)
    pg.hotkey('ctrl', 'v')



btn1 = tk.Button(root, text="Copy", font=("area", 25), height = 1, width = 10)
btn1.config(command=copy1)
btn1.pack()

btn2 = tk.Button(root, text="Paste", font=("area", 25), height = 1, width = 10)
btn2.config(command=paste1)
btn2.pack()

chbutton = tk.Checkbutton(root, text="Always On Top", 
font=("area", 12), variable=is_checked)
chbutton.config(command=alont)
chbutton.place(x=60, y=133.5)


root.mainloop()

有用於此的現有庫。 看到這個答案。 還有pyperclip。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM