Skip to content

Instantly share code, notes, and snippets.

@inclement
Created January 31, 2019 18:52
Show Gist options
  • Select an option

  • Save inclement/37693ac87d6b555b9839beffc0af1fd0 to your computer and use it in GitHub Desktop.

Select an option

Save inclement/37693ac87d6b555b9839beffc0af1fd0 to your computer and use it in GitHub Desktop.
from kivy.uix.widget import Widget
from kivy.lang import Builder
Builder.load_string("""
<RotatingWidget>:
on_size: self.reset_child()
on_pos: self.reset_child()
canvas.before:
PushMatrix:
Rotate:
angle: 90
origin: (self.right, self.y)
axis: 0, 0, 1
canvas.after:
PopMatrix:
""")
class RotatingWidget(Widget):
def reset_child(self):
"""Reposition our child so that it displays correctly."""
if not self.children:
print('No children to reset')
return
child = self.children[0]
child.width = self.height
child.height = self.width
child.pos = (self.right, self.y)
if __name__ == "__main__":
from kivy.base import runTouchApp
from kivy.uix.button import Button
rw = RotatingWidget()
rw.add_widget(Button(text='hello world'))
runTouchApp(rw)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment