jligeza
jligeza

Reputation: 4713

Swapping screens with motion in kivy

Is it possible to swap screens with motion, rather than on button press? I am asking in context of mobile applications, where this behaviour is often expected by users.

Upvotes: 1

Views: 155

Answers (2)

7stud
7stud

Reputation: 48659

I think this might be a better way to do things:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.carousel import Carousel
from kivy.lang import Builder

Builder.load_string("""
<MyCarousel>:
    BoxLayout:
        orientation: 'vertical'

        Label:
            text: "Screen 1"
        Label:
            text: "Some text"

    BoxLayout:
        orientation: 'vertical'

        Label:
            text: "Screen 2"
        BoxLayout:
            Button:
                text: "1"
            Button:
                text: "2"
            Button:
                text: "3"
            Button:
                text: "4"

    BoxLayout:
        orientation: 'vertical'

        Label:
            text: "Screen 3"
        Label:
            text: "Some other text"
""")

class MyCarousel(Carousel):
    pass

class MyApp(App):
    def build(self):
        return MyCarousel()

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

Apparently, a Carousel doesn't behave like other widgets as it doesn't have a default size of 100, 100.

Upvotes: 2

Nykakin
Nykakin

Reputation: 8747

You can use Carousel widget. For example:

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

Builder.load_string("""
<MyWidget>:
    Carousel:
        BoxLayout:
            orientation: 'vertical'
            Label:
                text: "Screen 1"
            Label:
                text: "Some text"
        BoxLayout:
            orientation: 'vertical'
            Label:
                text: "Screen 2"
            BoxLayout:
                Button:
                    text: "1"
                Button:
                    text: "2"
                Button:
                    text: "3"
                Button:
                    text: "4"
        BoxLayout:
            orientation: 'vertical'
            Label:
                text: "Screen 3"
            Label:
                text: "Some other text"
""")

class MyWidget(BoxLayout):
    pass

class MyApp(App):
    def build(self):
        return MyWidget()

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

Upvotes: 2

Related Questions