- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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.
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.
# 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()
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 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