2023年10月28日 星期六

Kivy screen篇 WipeTransition 講解

簡述

根據官方解釋:

Wipe transition, based on a fragment Shader. shader to wipe the screens from right to left.

具體效果可參考本文中的影片

基本範例

在main.py中寫上此段程式碼:

from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen, WipeTransition
from kivy.properties import ObjectProperty


class AScreen(Screen):
    pass


class BScreen(Screen):
    pass


class sm(ScreenManager):
    a1 = ObjectProperty(WipeTransition(duration=3))


class MyApp(App):

    def build(self):
        return sm()


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

在my.kv中寫上此段程式碼:

<AScreen>:
    name: 'menu'

    BoxLayout:

        Button:
            text: 'Goto settings'
            on_press: root.manager.current = 'settings'

        Label:
            text: str(root.transition_progress)


<BScreen>:
    name: 'settings'

    BoxLayout:

        Label:
            text: str(root.transition_progress)

        Button:
            text: 'still settings'
            on_press: root.manager.current = 'menu'


<sm>:
    transition: root.a1

    AScreen:

    BScreen:

執行結果如下:

WipeTransition使用技巧:

沒有

沒有留言:

張貼留言

精選文章

Kivy UIX篇 widget篇 TabbedPanel類 event篇 講解