Domas Mar
Domas Mar

Reputation: 1186

Is it possible to turn a widget [Kivy]

Does kivy have a function which could turn a widget.

For example I have a widget that draws a rectangle. Now the problem is it possible to turn that rectangle by 45 degree?

If it does not have, what would be the best aproach to achieve it?

Upvotes: 0

Views: 286

Answers (1)

paarth batra
paarth batra

Reputation: 1412

Yes its possible to rotate . You need to change the angle in the Rotate . See below sample code :

from kivy.app import App
from kivy.lang import Builder
from kivy.graphics import Color
from kivy.uix.boxlayout import BoxLayout


gui = '''
<MyWidget>:
    canvas:
        Rotate:
            axis: 0,0,1
            angle: 45
            origin: self.center
        Color:
            rgba: 0.4, 0.4, 0.4, 1
        Rectangle:
            pos: root.center
            size: (32, 32)
'''

class MyWidget(BoxLayout):
    def __init__(self, **kwargs):
        super(MyWidget, self).__init__(**kwargs)
    Builder.load_string(gui)

class MyJB(App):
    def build(self):
        parent = MyWidget()
        return parent

if __name__ == '__main__':
    MyJB().run()

Upvotes: 1

Related Questions