Parthib Biswas
Parthib Biswas

Reputation: 501

Forcing a Kivy widget's orientation to be landscape/portrait

I'm developing an app where I want one of ScreenManager's screen to be in landscape orientation. I don't want it to change to vertical by itself. As of now, what I learned is only buildozer.spec file can change the app's orientation. What I want is to change the widget's orientation. Is there any way to do this?

Upvotes: 1

Views: 4543

Answers (2)

Allamaris
Allamaris

Reputation: 21

Maybe it will be useful for someone. I use this:

BoxLayout:
    size_hint: None, None
    pos_hint: {'center_x': .5, 'center_y': .5}
    canvas.before:
        PushMatrix
        Rotate:
            angle: 90
            origin: self.center
    canvas.after:
        PopMatrix

With ScatterLayout I got message

[Critical][Clock ]Warning, too much iteration done before the next frame

Upvotes: 0

jligeza
jligeza

Reputation: 4693

You can place a content of the screen on a scatter layout, and then rotate it:

test.kv:

ScreenManager:

    Screen:
        name: 'normal'

        Grid

    Screen:
        name: 'flipped'

        ScatterLayout:
            do_rotation: False
            do_scale: False
            do_translation: False
            rotation: 90
            pos_hint: {'center_x': 0.5, 'center_y': 0.5}
            size_hint: None, None
            size: root.height, root.width

            Grid


<Grid@GridLayout>:
    cols: 1

    Button:
        text: 'normal'
        on_press: app.root.current = 'normal'
    Button:
        text: 'flipped'
        on_press: app.root.current = 'flipped'

main.py:

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from kivy.app import App


class Test(App):
    pass


Test().run()

@edit There is also plyer's Orientation.

Upvotes: 1

Related Questions