Skip to content

Instantly share code, notes, and snippets.

@tshirtman
Created February 4, 2020 13:24
Show Gist options
  • Save tshirtman/bddc8a3f79cc23718cd53244730eba98 to your computer and use it in GitHub Desktop.
Save tshirtman/bddc8a3f79cc23718cd53244730eba98 to your computer and use it in GitHub Desktop.
from kivy.app import App
from kivy.uix.scatter import Scatter
from kivy.lang import Builder
KV = '''
FloatLayout:
MyScatter:
size:1000, 1000
do_rotation: False
size_hint: None, None
auto_bring_to_front: False
Widget:
canvas:
Color:
Line:
rectangle: [0, 0, 300, 300]
Rectangle:
pos: 20, 20
size: 10, 10
Label:
id: my_label
text: '<-- Small rectangle top is here'
size_hint: None, None
size: self.texture_size
x: 30
center_y: self.height and 30
font_size: '20sp'
'''
class MyScatter(Scatter):
def on_transform_with_touch(self, touch):
#get the label
label = app.root.ids.my_label
#hardcoded pos,
#given the size and font of the label,
#this will point exactly to the small rectangles top
#...until the scatter is scaled
x, y = 30, 30
#move the label
label.x, label.center_y = self.to_parent(x, y)
class MyApp(App):
def build(self):
self.root = Builder.load_string(KV)
return self.root
if __name__ == "__main__":
app=MyApp()
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment