Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from kivy.app import App
- from kivy.lang import Builder
- from kivy.uix.boxlayout import BoxLayout
- from kivy.uix.scatter import Scatter
- from kivy.uix.widget import Widget
- Builder.load_string("""
- <MainWidget>
- Picture:
- size_hint: None, None
- width: 500
- height: 500
- canvas.before:
- Color:
- rgba: 1, 0, 0, 1
- Rectangle:
- pos: self.pos
- size: self.size
- MyWidget:
- size_hint: None, None
- width: 200
- height: 200
- pos: self.parent.right - (self.width/2), self.parent.top - (self.height/2)
- canvas.before:
- Color:
- rgba: 0, 1, 0, 1
- Rectangle:
- pos: self.pos
- size: self.size
- """)
- class Picture(Scatter):
- def on_touch_down(self, touch):
- super(Picture, self).on_touch_down(touch)
- print("Picture:" )
- print(" self.pos: {}".format(self.pos))
- print(" self.size: {}".format(self.size))
- print(" touch.pos: {}".format(touch.pos))
- class MyWidget(Widget):
- def on_touch_down(self, touch):
- print("MyWidget:")
- print(" self.pos: {}".format(self.pos))
- print(" self.size: {}".format(self.size))
- print(" touch.pos: {}".format(touch.pos))
- class MainWidget(BoxLayout):
- def __init__(self, **kwargs):
- super(MainWidget, self).__init__(**kwargs)
- class MyApp(App):
- def build(self):
- return MainWidget()
- if __name__ == '__main__' or __name__ == 'android':
- MyApp().run()
Add Comment
Please, Sign In to add comment