- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Copy from clipboard using Python and Tkinter
To copy from clipboard, we can use the clipboard_get() method of Tkinter. Let's take an example and see how to get the data from the clipboard and display it on a Tkinter window.
Steps −
Import the tkinter library and create an instance of tkinter frame.
Set the size of the frame using geometry method.
Next, call clipboard_get() to get the text from the clipboard and store the data in a variable "cliptext".
Create a label to the display the clipboard text. Pass cliptext as text, "text=cliptext".
Finally, run the mainloop of the application window.
Example
# Import the tkinter library from tkinter import * # Instance of tkinter canvas win = Tk() win.geometry("700x250") win.title("Data from Clipboard") # Get the data from the clipboard cliptext = win.clipboard_get() # Label to print clipboard text lab=Label(win, text = cliptext, font=("Calibri",15,"bold")) lab.pack(padx=20, pady=50) # Run the mainloop win.mainloop()
Output
It will produce the following output −
It will display the contents of the clipboard on the window.
- Related Articles
- How to copy from clipboard using tkinter without displaying a window
- Copy and paste to your clipboard using the pyperclip module in Python
- How to Print Hard Copy using Tkinter?
- How to copy text to the clipboard with JavaScript?
- How to secretly copy to clipboard JavaScript function in Chrome and Firefox?
- Creating ‘Copy to Clipboard’ feature on a web page with JavaScript
- How to exit from Python using a Tkinter Button?
- How to copy files from one folder to another using Python?
- How to copy files from one server to another using Python?
- How to Automatically Copy a Cell to Clipboard with a Single Click in Excel?
- How to copy certain files from one folder to another using Python?
- Getting screens height and width using Tkinter Python
- Copy - Shallow and deep copy operations in Python
- Word Dictionary using Python Tkinter
- Color game using Tkinter in Python

Advertisements