-1

How do I write a program with Python that can act as a copy and paste in Windows? I made two buttons with the python library and want to do one copy in the windows environment and the other one in the paste. Thanks for helping me.

its my code

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()

  • Hi @mehran, can you please share your python code that has the buttons, we can direct you to some library options, but it will depend on the version of python you are using. For example: there is tkinter and gtk (https://python-gtk-3-tutorial.readthedocs.io/en/latest/button_widgets.html) that you can create widgets and guis - it all depends. It is easy to add this information and edit the question when you have time. – Rachel McGuigan Mar 13 '20 at 23:33
  • Please see [ask], [help/on-topic]. – AMC Mar 14 '20 at 00:10

1 Answers1

-1

There are existing libraries for this. See this answer. There's also pyperclip.

crumb
  • 76
  • 1
  • 6
  • pyperclip not working in text editors or file manager or else, not work in windows enviroment – mehran jamal Mar 13 '20 at 23:23
  • @mehran jarnal It works in my environment. What issue are you having? There's also the solution offered in the other linked question through tkinter. – crumb Mar 14 '20 at 15:57
  • Is there a way to turn off my software focus? Never focus on my software. can i see your codes?? please – mehran jamal Mar 14 '20 at 23:15