- Kivy Tutorial
- Kivy - Home
- Kivy Basics
- Kivy - Getting Started
- Kivy - Installation
- Kivy - Architecture
- Kivy - File Syntax
- Kivy - Applications
- Kivy - Hello World
- Kivy - App Life Cycle
- Kivy - Events
- Kivy - Properties
- Kivy - Inputs
- Kivy - Behaviors
- Kivy Buttons
- Kivy - Buttons
- Kivy - Button Events
- Kivy - Button Colors
- Kivy - Button Size
- Kivy - Button Position
- Kivy - Round Buttons
- Kivy - Disabled Buttons
- Kivy - Image Button
- Kivy Widgets
- Kivy - Widgets
- Kivy - Label
- Kivy - Text Input
- Kivy - Canvas
- Kivy - Line
- Kivy - Checkbox
- Kivy - Dropdown List
- Kivy - Windows
- Kivy - ScrollView
- Kivy - Carousel
- Kivy - Slider
- Kivy - Images
- Kivy - Popup
- Kivy - Switch
- Kivy - Spinner
- Kivy - Splitter
- Kivy - Progress Bar
- Kivy - Bubble
- Kivy - Tabbed Panel
- Kivy - Scatter
- Kivy - Accordion
- Kivy - File Chooser
- Kivy - Color Picker
- Kivy - Code Input
- Kivy - Modal View
- Kivy - Toggle Button
- Kivy - Camera
- Kivy - Tree View
- Kivy - reStructuredText
- Kivy - Action Bar
- Kivy - Video Player
- Kivy - Stencil View
- Kivy - VKeyboard
- Kivy - Touch Ripple
- Kivy - Audio
- Kivy - Videos
- Kivy - Spelling
- Kivy - Effects
- Kivy - Input Recorder
- Kivy - OpenGL
- Kivy - Text
- Kivy - Text Markup
- Kivy - Settings
- Kivy Layouts
- Kivy - Layouts
- Kivy - Float Layout
- Kivy - Grid Layouts
- Kivy - Box Layouts
- Kivy - Stack Layout
- Kivy - Anchor Layout
- Kivy - Relative Layout
- Kivy - Page Layout
- Kivy - Recycle Layout
- Kivy - Layouts in Layouts
- Kivy Advanced Concepts
- Kivy - Configuration Object
- Kivy - Atlas
- Kivy - Data Loader
- Kivy - Cache Manager
- Kivy - Console
- Kivy - Animation
- Kivy - Multistroke
- Kivy - Clock
- Kivy - SVGs
- Kivy - UrlRequest
- Kivy - Clipboard
- Kivy - Factory
- Kivy - Gesture
- Kivy - Language
- Kivy - Graphics
- Kivy - Drawing
- Kivy - Packaging
- Kivy - Garden
- Kivy - Storage
- Kivy - Vector
- Kivy - Utils
- Kivy - Inspector
- Kivy - Tools
- Kivy - Logger
- Kivy - Framebuffer
- Kivy Applications and Projects
- Kivy - Drawing App
- Kivy - Calculator App
- Kivy - Stopwatch App
- Kivy - Camera Handling
- Kivy - Image Viewer
- Kivy - Bezier
- Kivy - Canvas Stress
- Kivy - Circle Drawing
- Kivy - Widget Animation
- Kivy - Miscellaneous
- Kivy Useful Resources
- Kivy - Quick Guide
- Kivy - Useful Resources
- Kivy - Discussion
Kivy - Clipboard
The Clipboard object in Kivy framework gives access to the clipboard of the operating system being used. With the help of Kivy's Clipboard object, one can perform programmatically the cut, copy and paste operations.
The clipboard is a temporary buffer in computer's RAM that most operating systems provide for short-term storage and transfer within and between application programs. In the operating system, this clipboard is a global object. Most operating systems use conventional keyboard shortcuts for carrying out cut, copy and paste data between applications.
Normally, the explicit use of the cut-copy-paste operations through the Clipboard is not necessary. However, in some cases it may be useful.
The Clipboard object is defined in the "kivy.core.clipboard" module. The following methods are available for Clipboard object −
copy() − Copy the value provided in argument data into current clipboard. If data is not of type string it will be converted to string.
get() − Get the current data in clipboard, using the mimetype if possible. You not use this method directly. Use paste method instead.
get_types() − Return a list of supported mimetypes.
paste() − Get text from the system clipboard and return it a usable string.
put() − Put data on the clipboard, and attach a mimetype. You should not use this method directly. Use copy method instead.
Example
In the following example, we have two multiline textboxes and two buttons arranged in a BoxLayout. The COPY button calls gettext() method which copies the selected text from the upper text box to the clipboard.
def gettext(self, instance): Clipboard.copy(data=self.text1.selection_text)
The PASTE button invokes a callback insert() which pastes the selected text at the cursor position.
def insert(self, instance): txt = Clipboard.paste() print (txt) self.text2.insert_text(txt)
These two functions are bound to two buttons −
self.b1=Button(text='COPY') self.b1.bind(on_press=self.gettext) self.b2=Button(text='PASTE') self.b2.bind(on_press=self.insert)
The build() method assembles the text boxes and buttons.
Here is the complete code for this exercise −
from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.uix.textinput import TextInput from kivy.uix.button import Button from kivy.core.clipboard import Clipboard from kivy.core.window import Window Window.size = (720, 400) class mydemoapp(App): def gettext(self, instance): Clipboard.copy(data=self.text1.selection_text) def insert(self, instance): txt = Clipboard.paste() print(txt) self.text2.insert_text(txt) def build(self): main = BoxLayout(orientation='vertical') self.text1 = TextInput(multiline=True, font_size=32) btns = BoxLayout(orientation='horizontal') self.b1 = Button(text='COPY') self.b1.bind(on_press=self.gettext) self.b2 = Button(text='PASTE') self.b2.bind(on_press=self.insert) self.text2 = TextInput( multiline=True, font_size=32, foreground_color=[0, 0, 1, 1] ) btns.add_widget(self.b1) btns.add_widget(self.b2) main.add_widget(self.text1) main.add_widget(btns) main.add_widget(self.text2) return main mydemoapp().run()
Output
When the program is run, you will observe two textboxes. Enter Simple is better than Complex in the upper box, and Complex is Complicated in the lower box.
Then, select the substring better than, and click the COPY button to store it on the clipboard. Click besides the word Complicated in the lower box, and click the PASTE button. The text on the clipboard will be inserted.
To Continue Learning Please Login
Login with Google