1import pyperclip
2pyperclip.copy('The text to be copied to the clipboard.')
1from tkinter import Tk
2
3def Copy(txt):
4 r = Tk()
5 r.withdraw()
6 r.clipboard_clear()
7 r.clipboard_append(str(txt))
8 r.update() # now it stays on the clipboard after the window is closed
9 r.destroy()
10Copy("It Works")
1import pyperclip
2pyperclip.copy('The text to be copied to the clipboard.')
3spam = pyperclip.paste()
4
1# To use native Python directories, use:
2from subprocess import check_call
3
4# On windows use:
5def copy2clip(txt):
6 cmd='echo '+txt.strip()+'|clip'
7 return check_call(cmd, shell=True)
8
9# On Mac use:
10def copy2clip(txt):
11 cmd='echo '+txt.strip()+'|pbcopy'
12 return check_call(cmd, shell=True)
13
14# Then to call the function use:
15copy2clip('This is on my clipboard!')