Skip to content

Instantly share code, notes, and snippets.

@onslauth
Last active January 17, 2019 13:28
Show Gist options
  • Save onslauth/71d4f12b6227fa1787a35ea32fbfe9f0 to your computer and use it in GitHub Desktop.
Save onslauth/71d4f12b6227fa1787a35ea32fbfe9f0 to your computer and use it in GitHub Desktop.
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment