Advertisement
jwinterm

KivyClipboardExample

Jun 13th, 2014
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. from kivy.app import App
  2. from kivy.lang import Builder
  3. from kivy.uix.boxlayout import BoxLayout
  4. from kivy.core.clipboard import Clipboard
  5. from kivy.properties import ObjectProperty
  6. import sys
  7.  
  8.  
  9. Builder.load_string('''
  10. #:kivy 1.8.0
  11.  
  12. <RootWidget>:
  13.    label_text: label_text
  14.    Label:
  15.        id: label_text
  16.        markup: True
  17.        text: '[ref=text_selection]initial[/ref]'
  18.        on_ref_press: root.copytext()
  19.    TextInput:
  20.        
  21.        ''')
  22.  
  23.  
  24. class RootWidget(BoxLayout):
  25.     """Root Kivy widget class"""
  26.     label_text = ObjectProperty()
  27.  
  28.     def __init__(self):
  29.         super(RootWidget, self).__init__()
  30.    
  31.     def copytext(self):
  32.             """copy address to clipboard when user clicks"""
  33.             text = self.label_text.text
  34.             print('User clicked on ', text)
  35.             Clipboard.put(text)
  36.  
  37.  
  38.  
  39. class ExampleApp(App):
  40.     def build(self):
  41.         return RootWidget()
  42.  
  43.  
  44. if __name__ == '__main__':
  45.     ExampleApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement