import sys
try:
from Tkinter import Tk
except ImportError:
# welcome to Python3
from tkinter import Tk
raw_input = input
r = Tk()
r.withdraw()
r.clipboard_clear()
if len(sys.argv) < 2:
data = sys.stdin.read()
else:
data = ' '.join(sys.argv[1:])
r.clipboard_append(data)
if sys.platform != 'win32':
if len(sys.argv) > 1:
raw_input('Data was copied into clipboard. Paste and press ENTER to exit...')
else:
# stdin already read; use GUI to exit
print('Data was copied into clipboard. Paste, then close popup to exit...')
r.deiconify()
r.mainloop()
else:
r.destroy()
from PyQt5.QtWidgets import QApplication
import sys
def main():
app = QApplication(sys.argv)
cb = QApplication.clipboard()
cb.clear(mode=cb.Clipboard )
cb.setText("Copy to ClipBoard", mode=cb.Clipboard)
# Text is now already in the clipboard, no need for further actions.
sys.exit()
if __name__ == "__main__":
main()
import clipboard
clipboard.copy("abc") # now the clipboard content will be string "abc"
text = clipboard.paste() # text will have the content of clipboard