i'm trying to rotate some pictures i have to show on the screen, these picture are inside a stacklayout, and i need to show them as Portrait instead of landscape,i'm using the Image Widget Thanks
The previous 2 answer of toto_tico is a way to do, but i would rather create a new widget for it, and use it:
Builder.load_string('''
<RotatedImage>:
canvas.before:
PushMatrix
Rotate:
angle: root.angle
axis: 0, 0, 1
origin: root.center
canvas.after:
PopMatrix
''')
class RotatedImage(Image):
angle = NumericProperty()
Then, use this widget as other Image widget, you just have a "angle" property you can play with.
Note: the collision detection is not handled on the image, except in the scatter example. Scatter can be expensive just for rotate something, but at least the collision works.
I don't think the Scatter is meant to be use for this. But I guess is a more intuitive solution. The Scatter includes a rotation (and also a scale) property.
Basically, I embedded the Image inside a Scatter and use the rotation property to rotate 90 degrees.
Why do I say the Scatter is not meant for this task. Basically because it allows gestures over it. You can basically translate, rotate or scale with your fingers (or using the multi-touch mouse emulation). That is why in the next example I am setting the do_scale
, do_rotation
and do_translation
to false. I am clarifying this before you get confuse with the do_rotation: false
from kivy.app import App
from kivy.uix.stacklayout import StackLayout
from kivy.lang import Builder
Builder.load_string("""
<Example>:
Image:
source: 'kivy.png'
size_hint: None,None
size: 64,64
Scatter:
pos: 0,0
size_hint: None,None
size: 64,64
do_rotation: False
do_scale: False
do_translation: False
rotation: 90
Image:
source: 'kivy.png'
size_hint: None,None
size: 64,64
""")
class Example(App, StackLayout):
def build(self):
return self
if __name__ == "__main__":
Example().run()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With