Skip to content

Instantly share code, notes, and snippets.

@kived
Created March 17, 2015 17:36
Show Gist options
  • Save kived/4094c5df0b4a791eedbe to your computer and use it in GitHub Desktop.
Save kived/4094c5df0b4a791eedbe to your computer and use it in GitHub Desktop.
Kivy: Rotation in Python
'''
Rotation Example
================
This example rotates a button using PushMatrix and PopMatrix. You should see
a static button with the words 'hello world' rotated at a 45 degree angle.
'''
from kivy.app import App
from kivy.lang import Builder
from kivy.graphics import *
kv = '''
FloatLayout:
Button:
text: 'hello world'
size_hint: None, None
pos_hint: {'center_x': .5, 'center_y': .5}
#canvas.before:
# PushMatrix
# Rotate:
# angle: 45
# origin: self.center
#canvas.after:
# PopMatrix
'''
class RotationApp(App):
def build(self):
root = Builder.load_string(kv)
btn = root.children[0]
with btn.canvas.before:
PushMatrix()
rotate = Rotate(angle=45)
with btn.canvas.after:
PopMatrix()
def update_rotate(w, center):
rotate.origin = center
btn.bind(center=update_rotate)
return root
RotationApp().run()
@OlyDLG
Copy link

OlyDLG commented Mar 17, 2015

Excellent, thanks!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment