- 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.
Advertisements