Created
March 17, 2015 17:36
-
-
Save kived/4094c5df0b4a791eedbe to your computer and use it in GitHub Desktop.
Kivy: Rotation in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Excellent, thanks!!!