Skip to content Skip to sidebar Skip to footer

How To Read Data From Clipboard And Pass It As Value To A Variable In Python?

how to read data from clipboard and pass it as value to a variable in python? For example: I will copy some data {eg: 200} by pressing ctrl+c or through rightclick. and pass it to

Solution 1:

To read from clipboard in your script with tkinter is this easy:

try:
    # Python2import Tkinter as tk
except ImportError:
    # Python3import tkinter as tk

root = tk.Tk()
# keep the window from showing
root.withdraw()

# read the clipboard
c = root.clipboard_get()

Solution 2:

Just put this script in your path somewhere, say in your project folder, then;

import pyperclip # The name you have the file
x = pyperclip.paste()

Solution 3:

This is only for Windows OS!!

In C++ : Use GetData by using namespace of Systems.Windows See this link http://msdn.microsoft.com/en-us/library/system.windows.clipboard.aspx

And for python, you can use gtk or Pygtk libraries to do the same task! For example:

gtk.Clipboard()

Post a Comment for "How To Read Data From Clipboard And Pass It As Value To A Variable In Python?"