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