- 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
How do I paste the copied text from the keyboard in Python?
Python offers many built-in libraries and modules which provides a way to implement the additional features in developing various python applications. pyperclip is one of the cross-platform python modules to implement the copyandpaste operation in any Python application. To use it in Python application, you've to install it using the following command,
pip install pyperclip
The practical use-case can be implemented by developing an application which copies the text from the clipboard and displays on the screen. Additionally, we can also display the copied text in an Entry widget or Text widget which accepts the user input in the form of text.
Example
Let us understand this with an example.
# Import required libraries from tkinter import * import pyperclip # Create an instance of tkinter frame or window win = Tk() # Set the size of the window win.geometry("700x350") # Create a text widget my_clip= Text(win, height=15) my_clip.pack() def update_text(): global my_clip my_clip.insert(END,pyperclip.paste()) # Create a button to paste the copied text from clipboard button=Button(win, text= "Paste Here", command=update_text) button.pack() win.mainloop()
Output
If you run the above code snippet, it will display a window with a button and a text editor where the copied text is pasted and displayed.
- Related Articles
- How do I center the text in a Tkinter Text widget?
- Python Tkinter – How do I change the text size in a label widget?
- How do I Input a String From the User in Python?
- Include keyboard text in HTML
- Move the text field when the keyboard appears in Swift
- How do you hide the onscreen keyboard in iOS App?
- How do I disable log messages from the Requests Python module?
- How do I give focus to a python Tkinter text widget?
- How do I display only the visible text with jQuery?
- How do I use Tkinter in Python to create line-wrapped text that fills the width of the window?
- How do I create documentation from doc strings in Python?
- How do I remove a substring from the end of a string in Python?
- How do I find an element that contains specific text in Selenium WebDriver (Python)?
- How do I get the parent directory in Python?
- How do I call a Variable from Another Function in Python?
