https://kivy.org/doc/stable/api-kivy.uix.screenmanager.html#module-kivy.uix.screenmanager
Screen Manager¶
Module: kivy.uix.screenmanager
Added in 1.0.0
New in version 1.4.0.
The screen manager is a widget dedicated to managing multiple screens for your application. The default ScreenManager displays only one Screen at a time and uses a TransitionBase to switch from one Screen to another.
屏幕管理器是一个专门用于管理应用程序中多个屏幕的控件。默认的屏幕管理器一次只显示一个屏幕,并使用TransitionBase
来从一个屏幕切换到另一个屏幕。
Multiple transitions are supported based on changing the screen coordinates / scale or even performing fancy animation using custom shaders.
支持多种过渡效果,这些效果可以通过改变屏幕的坐标/比例来实现,甚至可以使用自定义着色器来执行复杂的动画。
Basic Usage¶
Let’s construct a Screen Manager with 4 named screens. When you are creating a screen, you absolutely need to give a name to it:
让我们构建一个包含4个命名屏幕的屏幕管理器。在创建屏幕时,您绝对需要给它一个名字:
from kivy.uix.screenmanager import ScreenManager, Screen # Create the manager sm = ScreenManager() # Add few screens for i in range(4): screen = Screen(name='Title %d' % i) sm.add_widget(screen) # By default, the first screen added into the ScreenManager will be # displayed. You can then change to another screen. # Let's display the screen named 'Title 2' # A transition will automatically be used. sm.current = 'Title 2'
The default ScreenManager.transition is a SlideTransition with options direction and duration.
默认的ScreenManager.transition
是一个SlideTransition
,它带有direction
和duration
选项。
Please note that by default, a Screen displays nothing: it’s just a RelativeLayout. You need to use that class as a root widget for your own screen, the best way being to subclass.
请注意,默认情况下,一个Screen
不显示任何内容:它只是一个RelativeLayout
。您需要将该类用作您自己屏幕的根控件,最好的方法是进行子类化。
Warning
As Screen is a RelativeLayout, it is important to understand the Common Pitfalls.
由于Screen
是一个RelativeLayout
,因此了解它的“常见陷阱”是很重要的。
Here is an example with a ‘Menu Screen’ and a ‘Settings Screen’:
from kivy.app import App from kivy.lang import Builder from kivy.uix.screenmanager import ScreenManager, Screen # Create both screens. Please note the root.manager.current: this is how # you can control the ScreenManager from kv. Each screen has by default a # property manager that gives you the instance of the ScreenManager used. Builder.load_string(""" <MenuScreen>: BoxLayout: Button: text: 'Goto settings' on_press: root.manager.current = 'settings' Button: text: 'Quit' <SettingsScreen>: BoxLayout: Button: text: 'My settings button' Button: text: 'Back to menu' on_press: root.manager.current = 'menu' """) # Declare both screens class MenuScreen(Screen): pass class SettingsScreen(Screen): pass class TestApp(App): def build(self): # Create the screen manager sm = ScreenManager() sm.add_widget(MenuScreen(name='menu')) sm.add_widget(SettingsScreen(name='settings')) return sm if __name__ == '__main__': TestApp().run()
Changing Direction¶
A common use case for ScreenManager involves using a SlideTransition which slides right to the next screen and slides left to the previous screen. Building on the previous example, this can be accomplished like so:ScreenManager
的一个常见用例包括使用SlideTransition
,该过渡效果在滑向下一个屏幕时向右滑动,在滑向上一个屏幕时向左滑动。基于之前的例子,这可以通过以下方式实现:
Builder.load_string(""" <MenuScreen>: BoxLayout: Button: text: 'Goto settings' on_press: root.manager.transition.direction = 'left' root.manager.current = 'settings' Button: text: 'Quit' <SettingsScreen>: BoxLayout: Button: text: 'My settings button' Button: text: 'Back to menu' on_press: root.manager.transition.direction = 'right' root.manager.current = 'menu' """)
Advanced Usage¶
From 1.8.0, you can now switch dynamically to a new screen, change the transition options and remove the previous one by using switch_to():
从1.8.0版本开始,您现在可以使用switch_to()
函数动态地切换到新屏幕,更改过渡选项,并移除之前的屏幕:
sm = ScreenManager() screens = [Screen(name='Title {}'.format(i)) for i in range(4)] sm.switch_to(screens[0]) # later sm.switch_to(screens[1], direction='right')
Note that this method adds the screen to the ScreenManager instance and should not be used if your screens have already been added to this instance. To switch to a screen which is already added, you should use the current property.
请注意,此方法会将screen
添加到ScreenManager
实例中,如果您的screens
已经添加到了此实例中,则不应使用此方法。要切换到已经添加的屏幕,您应该使用current
属性。
Changing transitions¶
You have multiple transitions available by default, such as:
默认情况下,您可以使用多种过渡效果,例如:
-
NoTransition - switches screens instantly with no animation
NoTransition
- 瞬间切换屏幕,没有动画效果 -
SlideTransition - slide the screen in/out, from any direction
SlideTransition
- 以任何方向滑入/滑出屏幕 -
CardTransition - new screen slides on the previous or the old one slides off the new one depending on the mode
CardTransition
- 根据模式,新屏幕会在旧屏幕上滑动进入,或者旧屏幕从新屏幕上滑出。 -
SwapTransition - implementation of the iOS swap transition
SwapTransition
- iOS风格的交换过渡效果实现。 -
FadeTransition - shader to fade the screen in/out
FadeTransition
- 使用着色器实现屏幕的淡入淡出效果。 -
WipeTransition - shader to wipe the screens from right to left
WipeTransition
- 使用着色器从右向左擦拭屏幕以实现过渡。 -
FallOutTransition - shader where the old screen ‘falls’ and becomes transparent, revealing the new one behind it.
FallOutTransition
- 使用着色器使旧屏幕“落下”并变得透明,从而揭示背后的新屏幕。 -
RiseInTransition - shader where the new screen rises from the screen centre while fading from transparent to opaque.
RiseInTransition
- 使用着色器使新屏幕从屏幕中心升起,同时从透明渐变到不透明。
You can easily switch transitions by changing the ScreenManager.transition property:
您可以通过更改ScreenManager.transition
属性来轻松切换过渡效果:
sm = ScreenManager(transition=FadeTransition())
Note
Currently, none of Shader based Transitions use anti-aliasing. This is because they use the FBO which doesn’t have any logic to handle supersampling. This is a known issue and we are working on a transparent implementation that will give the same results as if it had been rendered on screen.
目前,所有基于着色器的过渡效果都不使用抗锯齿。这是因为它们使用了帧缓冲对象(FBO),而帧缓冲对象没有处理超采样的逻辑。这是一个已知的问题,我们正在致力于实现一个透明的解决方案,以提供与直接在屏幕上渲染相同的结果。
To be more concrete, if you see sharp edged text during the animation, it’s normal.
更具体地说,如果您在动画过程中看到文字边缘很锐利,那么这是正常现象。
APIHide Description ⇑
class kivy.uix.screenmanager.CardTransition¶
Bases: kivy.uix.screenmanager.SlideTransition
Card transition that looks similar to Android 4.x application drawer interface animation.
卡片过渡效果,看起来类似于Android 4.x的应用程序抽屉界面的动画。
It supports 4 directions like SlideTransition: left, right, up and down, and two modes, pop and push. If push mode is activated, the previous screen does not move, and the new one slides in from the given direction. If the pop mode is activated, the previous screen slides out, when the new screen is already on the position of the ScreenManager.
它支持四个方向,类似于滑动过渡(SlideTransition):左、右、上和下,以及两种模式:弹出(pop)和推入(push)。如果启用了推入模式,前一个屏幕不会移动,而新屏幕会从给定的方向滑入。如果启用了弹出模式,则当新屏幕已经在屏幕管理器(ScreenManager)的位置上时,前一个屏幕会滑出。
New in version 1.10.
mode¶
Indicates if the transition should push or pop the screen on/off the ScreenManager.
指示过渡效果是否应该以推入(push)或弹出(pop)的方式将屏幕加入或移出屏幕管理器。
-
‘push’ means the screen slides in in the given direction
“push”意味着屏幕在给定的方向上滑入。 -
‘pop’ means the screen slides out in the given direction
“pop”意味着屏幕在给定的方向上滑出。
mode is an OptionProperty and defaults to ‘push’.mode
是一个OptionProperty
,默认值为‘push’。
start(manager)¶
(internal) Starts the transition. This is automatically called by the ScreenManager.
(内部)开始过渡。这是由ScreenManager
自动调用的。
class kivy.uix.screenmanager.FadeTransition¶
Bases: kivy.uix.screenmanager.ShaderTransition
Fade transition, based on a fragment Shader.
基于片段着色器的淡入淡出过渡效果。
fs¶
Fragment shader to use. 要使用的片段着色器。
fs is a StringProperty and defaults to None. fs
是一个StringProperty
,默认值为None
。
class kivy.uix.screenmanager.FallOutTransition¶
Bases: kivy.uix.screenmanager.ShaderTransition
Transition where the new screen ‘falls’ from the screen centre, becoming smaller and more transparent until it disappears, and revealing the new screen behind it. Mimics the popular/standard Android transition.
这种过渡效果是新屏幕从屏幕中心“落下”,同时变小并变得更加透明,直到它消失,从而揭示出它背后的新屏幕。它模仿了流行的/标准的Android过渡效果。
New in version 1.8.0.
duration¶
Duration in seconds of the transition, replacing the default of TransitionBase.
过渡效果的持续时间(以秒为单位),替代TransitionBase
的默认值。
duration is a NumericProperty and defaults to .15 (= 150ms).duration
是一个NumericProperty
,默认值为0.15(= 150毫秒)。
fs¶
Fragment shader to use. 要使用的片段着色器。
fs is a StringProperty and defaults to None. fs
是一个StringProperty
,默认值为None
。
class kivy.uix.screenmanager.NoTransition¶
Bases: kivy.uix.screenmanager.TransitionBase
No transition, instantly switches to the next screen with no delay or animation.
无过渡效果,立即且无延迟或动画地切换到下一个屏幕。
New in version 1.8.0.
duration¶
Duration in seconds of the transition. 过渡效果的持续时间(以秒为单位)。
duration is a NumericProperty and defaults to .4 (= 400ms).duration
是一个NumericProperty
,默认值为0.4(= 400毫秒)。
Changed in version 1.8.0: Default duration has been changed from 700ms to 400ms.
在版本1.8.0中更改:默认持续时间已从700毫秒更改为400毫秒。
class kivy.uix.screenmanager.RiseInTransition¶
Bases: kivy.uix.screenmanager.ShaderTransition
Transition where the new screen rises from the screen centre, becoming larger and changing from transparent to opaque until it fills the screen. Mimics the popular/standard Android transition.
这种过渡效果是新屏幕从屏幕中心升起,同时变大并从透明变为不透明,直到它填满整个屏幕。它模仿了流行的/标准的Android过渡效果。
New in version 1.8.0.
duration¶
Duration in seconds of the transition, replacing the default of TransitionBase.
过渡效果的持续时间(以秒为单位),替代TransitionBase
的默认值。
duration is a NumericProperty and defaults to .2 (= 200ms).duration
是一个NumericProperty
,默认值为0.2(= 200毫秒)。
fs¶
Fragment shader to use. 要使用的片段着色器。
fs is a StringProperty and defaults to None. fs
是一个StringProperty
,默认值为None
。
class kivy.uix.screenmanager.Screen(**kw)¶
Bases: kivy.uix.relativelayout.RelativeLayout
Screen is an element intended to be used with a ScreenManager. Check module documentation for more information.Screen
是一个元素,旨在与ScreenManager
一起使用。有关更多信息,请参阅模块文档。
Events:
on_pre_enter: ()
Event fired when the screen is about to be used: the entering animation is started.
当屏幕即将被使用时触发此事件:开始进入动画。
on_enter: ()
Event fired when the screen is displayed: the entering animation is complete.
当屏幕被显示时触发此事件:进入动画已完成。
on_pre_leave: ()
Event fired when the screen is about to be removed: the leaving animation is started.
当屏幕即将被移除时触发此事件:开始离开动画。
on_leave: ()
Event fired when the screen is removed: the leaving animation is finished.
当屏幕被移除时触发此事件:离开动画已完成。
Changed in version 1.6.0: Events on_pre_enter, on_enter, on_pre_leave and on_leave were added.
manager¶
ScreenManager object, set when the screen is added to a manager.ScreenManager
对象,当屏幕被添加到一个管理器时设置。
manager is an ObjectProperty and defaults to None, read-only.manager
是一个ObjectProperty
,默认值为None
,只读。
name¶
Name of the screen which must be unique within a ScreenManager. This is the name used for ScreenManager.current.
在ScreenManager
中必须唯一的屏幕名称。这是用于ScreenManager.current
的名称。
name is a StringProperty and defaults to ‘’.name
是一个StringProperty
,默认值为空字符串(''
)。
transition_progress¶
Value that represents the completion of the current transition, if any is occurring.
该值表示当前过渡效果的完成度(如果有的话)。
If a transition is in progress, whatever the mode, the value will change from 0 to 1. If you want to know if it’s an entering or leaving animation, check the transition_state.
如果过渡效果正在进行中,无论其模式如何,该值将从0变化到1。如果你想知道是进入动画还是离开动画,请检查transition_state
。
transition_progress is a NumericProperty and defaults to 0.transition_progress
是一个NumericProperty
,默认值为0。
transition_state¶
Value that represents the state of the transition: 该值表示过渡效果的状态:
-
‘in’ if the transition is going to show your screen
如果过渡效果将显示你的屏幕,则为‘in’ -
‘out’ if the transition is going to hide your screen
如果过渡效果将隐藏你的屏幕,则为‘out’
After the transition is complete, the state will retain its last value (in or out).
过渡效果完成后,该状态将保留其最后一个值(in或out)。
transition_state is an OptionProperty and defaults to ‘out’.transition_state
是一个OptionProperty
,默认值为‘out’。
class kivy.uix.screenmanager.ScreenManager(**kwargs)¶
Bases: kivy.uix.floatlayout.FloatLayout
Screen manager. This is the main class that will control your Screen stack and memory.
屏幕管理器。这是控制你的屏幕堆栈和内存的主要类。
By default, the manager will show only one screen at a time.
默认情况下,管理器一次只显示一个屏幕。
add_widget(widget, *args, **kwargs)¶
Changed in version 2.1.0: Renamed argument screen to widget.
在版本2.1.0中更改:将参数名从screen
更改为widget
。
clear_widgets(children=None, *args, **kwargs)¶
Changed in version 2.1.0: Renamed argument screens to children.
在版本2.1.0中更改:将参数名从screens
更改为children
。
current¶
Name of the screen currently shown, or the screen to show.
当前显示的屏幕的名称,或者要显示的屏幕的名称。
from kivy.uix.screenmanager import ScreenManager, Screen
sm = ScreenManager()
sm.add_widget(Screen(name='first'))
sm.add_widget(Screen(name='second'))
# By default, the first added screen will be shown. If you want to
# show another one, just set the 'current' property.
sm.current = 'second'
current is a StringProperty and defaults to None. current
是一个 StringProperty
,默认值为 None
。
current_screen¶
Contains the currently displayed screen. You must not change this property manually, use current instead.
包含当前显示的屏幕。你不应手动更改此属性,而应使用 current
代替。
current_screen is an ObjectProperty and defaults to None, read-only.current_screen
是一个 ObjectProperty
,默认值为 None
,只读。
get_screen(name)¶
Return the screen widget associated with the name or raise a ScreenManagerException if not found.
返回与给定名称相关联的屏幕小部件,如果未找到则引发 ScreenManagerException
异常。
has_screen(name)¶
Return True if a screen with the name has been found.
如果找到具有指定名称的屏幕,则返回 True
New in version 1.6.0. 此功能在版本 1.6.0 中新增。
next()¶
Return the name of the next screen from the screen list. 从屏幕列表中返回下一个屏幕的名称。
on_motion(etype, me)¶
Called when a motion event is received. 当接收到运动事件时被调用。
Parameters:
etype: str
Event type, one of “begin”, “update” or “end” 事件类型,为“begin”、“update”或“end”之一。
me: MotionEvent
Received motion event 接收到的运动事件。
Returns:
bool True to stop event dispatching bool True
用于停止事件分发
New in version 2.1.0. 在版本 2.1.0 中新增。
Warning 警告
This is an experimental method and it remains so while this warning is present.
这是一个实验性方法,只要此警告存在,它就将保持为实验性。
on_touch_down(touch)¶
Receive a touch down event. 接收触摸按下事件。
Parameters: 参数:
touch: MotionEvent class
Touch received. The touch is in parent coordinates. See relativelayout for a discussion on coordinate systems.
接收到的触摸。触摸是在父坐标中的。关于坐标系统,请参阅 RelativeLayout
的讨论。
Returns:
bool If True, the dispatching of the touch event will stop. If False, the event will continue to be dispatched to the rest of the widget tree.
bool 如果为 True,则停止分发触摸事件。如果为 False,则事件将继续分发给小部件树的其他部分。
on_touch_move(touch)¶
Receive a touch move event. The touch is in parent coordinates.
接收触摸移动事件。触摸是在父坐标中的。
See on_touch_down() for more information.
请参阅 on_touch_down()
以获取更多信息。
on_touch_up(touch)¶
Receive a touch up event. The touch is in parent coordinates.
接收触摸释放事件。触摸是在父坐标中的。
See on_touch_down() for more information.
请参阅 on_touch_down()
以获取更多信息。
previous()¶
Return the name of the previous screen from the screen list.
返回屏幕列表中前一个屏幕的名称。
remove_widget(widget, *args, **kwargs)¶
Remove a widget from the children of this widget.
从该小部件的子小部件中移除一个小部件。
Parameters:
widget:
Widget
Widget to remove from our children list. 要从我们的子小部件列表中移除的小部件。
from kivy.uix.button import Button
root = Widget()
button = Button()
root.add_widget(button)
root.remove_widget(button)
screen_names¶
List of the names of all the Screen widgets added. The list is read only.
所有已添加的Screen
小部件的名称列表。该列表是只读的。
screens_names
is an AliasProperty and is read-only. It is updated if the screen list changes or the name of a screen changes.screens_names
是一个AliasProperty
,并且是只读的。如果screen
列表更改或某个屏幕的名称更改,它将被更新。
screens¶
List of all the Screen widgets added. You should not change this list manually. Use the add_widget method instead.
所有已添加的Screen
小部件的列表。你不应手动更改此列表,而应使用add_widget
方法。
screens is a ListProperty and defaults to [], read-only.screens
是一个ListProperty
,默认为空列表([]
),并且是只读的。
switch_to(screen, **options)¶
Add a new or existing screen to the ScreenManager and switch to it. The previous screen will be “switched away” from. options are the transition options that will be changed before the animation happens.
将一个新屏幕或现有屏幕添加到ScreenManager
并切换到它。之前的屏幕将被“切换掉”。options
是在动画发生之前将更改的过渡选项。
If no previous screens are available, the screen will be used as the main one:
如果没有可用的先前屏幕,则此屏幕将用作主屏幕:
sm = ScreenManager()
sm.switch_to(screen1)
# later
sm.switch_to(screen2, direction='left')
# later
sm.switch_to(screen3, direction='right', duration=1.)
If any animation is in progress, it will be stopped and replaced by this one: you should avoid this because the animation will just look weird. Use either switch_to() or current but not both.
如果任何动画正在进行中,它将被停止并被这个动画替换:你应该避免这样做,因为动画看起来会很奇怪。使用switch_to()
或current
,但不要同时使用两者。
The screen name will be changed if there is any conflict with the current screen.
如果与当前屏幕存在任何冲突,screen
的名称将被更改。
transition¶
Transition object to use for animating the transition from the current screen to the next one being shown.
用于将当前屏幕动画过渡到下一个要显示的屏幕的过渡对象。
For example, if you want to use a WipeTransition between slides:
例如,如果你想在幻灯片之间使用WipeTransition
:
from kivy.uix.screenmanager import ScreenManager, Screen,
WipeTransition
sm = ScreenManager(transition=WipeTransition())
sm.add_widget(Screen(name='first'))
sm.add_widget(Screen(name='second'))
# by default, the first added screen will be shown. If you want to
# show another one, just set the 'current' property.
sm.current = 'second'
transition is an ObjectProperty and defaults to a SlideTransition.transition
是一个 ObjectProperty
,默认值为 SlideTransition
。
Changed in version 1.8.0: Default transition has been changed from SwapTransition to SlideTransition.
在版本 1.8.0 中更改:默认过渡已从 SwapTransition
更改为 SlideTransition
。
exception kivy.uix.screenmanager.ScreenManagerException¶
Bases: Exception
Exception for the ScreenManager.
class kivy.uix.screenmanager.ShaderTransition¶
Bases: kivy.uix.screenmanager.TransitionBase
Transition class that uses a Shader for animating the transition between 2 screens. By default, this class doesn’t assign any fragment/vertex shader. If you want to create your own fragment shader for the transition, you need to declare the header yourself and include the “t”, “tex_in” and “tex_out” uniform:
Transition
类使用 Shader 来在两个屏幕之间进行动画过渡。默认情况下,这个类不分配任何片段/顶点着色器。如果你想要为过渡创建自己的片段着色器,你需要自己声明头部,并包含“t”、“tex_in”和“tex_out”这三个统一变量(uniform):
- “t” 通常用于表示过渡的进度,它是一个从 0(开始)到 1(结束)的浮点数。
- “tex_in” 是输入纹理的采样器(sampler),代表当前屏幕(或前一个屏幕)的纹理。
- “tex_out” 是输出纹理的采样器,代表下一个屏幕(或新屏幕)的纹理。
通过编写自定义的片段着色器,你可以控制这两个屏幕在过渡期间如何混合和显示,从而创建独特的视觉效果。这需要对 OpenGL ES 和着色器编程有一定的了解。
# Create your own transition. This shader implements a "fading"
# transition.
fs = """$HEADER
uniform float t;
uniform sampler2D tex_in;
uniform sampler2D tex_out;
void main(void) {
vec4 cin = texture2D(tex_in, tex_coord0);
vec4 cout = texture2D(tex_out, tex_coord0);
gl_FragColor = mix(cout, cin, t);
}
"""
# And create your transition
tr = ShaderTransition(fs=fs)
sm = ScreenManager(transition=tr)
add_screen(screen)¶
(internal) Used to add a screen to the ScreenManager.
(内部使用)用于将屏幕添加到ScreenManager
。
clearcolor¶
Sets the color of Fbo ClearColor. 设置Fbo ClearColor的颜色。设置Fbo ClearColor的颜色。
New in version 1.9.0. 在版本1.9.0中新增。
clearcolor is a ColorProperty and defaults to [0, 0, 0, 1].clearcolor
是一个ColorProperty
,默认值为[0, 0, 0, 1](即黑色,不透明)。
Changed in version 2.0.0: Changed from ListProperty to ColorProperty.
在版本2.0.0中更改:从ListProperty
更改为ColorProperty
。
fs¶
Fragment shader to use. 片段着色器(Fragment Shader)用于渲染。
fs is a StringProperty and defaults to None. fs
是一个 StringProperty
,默认值为 None
。
remove_screen(screen)¶
(internal) Used to remove a screen from the ScreenManager.
(内部使用)用于从ScreenManager
中移除一个屏幕。
stop()¶
(internal) Stops the transition. This is automatically called by the ScreenManager.
(内部使用)停止过渡。这会被ScreenManager
自动调用。
vs¶
Vertex shader to use. 顶点着色器(Vertex Shader)用于处理。
vs is a StringProperty and defaults to None. vs
是一个 StringProperty
,默认值为 None
。
class kivy.uix.screenmanager.SlideTransition¶
Bases: kivy.uix.screenmanager.TransitionBase
Slide Transition, can be used to show a new screen from any direction: left, right, up or down.
滑动过渡(Slide Transition),可以用于从任何方向(左、右、上或下)显示一个新屏幕。
direction¶
Direction of the transition. 过渡的方向。
direction is an OptionProperty and defaults to ‘left’. Can be one of ‘left’, ‘right’, ‘up’ or ‘down’.direction
是一个 OptionProperty
,默认值为 'left'
。可是 'left'
、'right'
、'up'
或 'down'
中的一个。
class kivy.uix.screenmanager.SwapTransition(**kwargs)¶
Bases: kivy.uix.screenmanager.TransitionBase
Swap transition that looks like iOS transition when a new window appears on the screen.
交换过渡(Swap Transition),看起来像是iOS中当新窗口出现在屏幕上时的过渡效果。
add_screen(screen)¶
(internal) Used to add a screen to the ScreenManager.
(内部使用)用于将屏幕添加到ScreenManager
。
start(manager)¶
(internal) Starts the transition. This is automatically called by the ScreenManager.
(内部使用)开始过渡。这会被ScreenManager
自动调用。
class kivy.uix.screenmanager.TransitionBase¶
Bases: kivy.event.EventDispatcher
TransitionBase is used to animate 2 screens within the ScreenManager. This class acts as a base for other implementations like the SlideTransition and SwapTransition.TransitionBase
用于在ScreenManager
内对两个屏幕进行动画过渡。这个类作为其他实现(如SlideTransition
和SwapTransition
)的基类。
Events: 事件:
on_progress: Transition object, progression floaton_progress
: 过渡对象,进度浮点数
Fired during the animation of the transition.
在过渡动画进行期间触发。
on_complete: Transition object on_complete
: 过渡对象
Fired when the transition is finished.
当过渡完成时触发。
add_screen(screen)¶
(internal) Used to add a screen to the ScreenManager.
(内部使用)用于将屏幕添加到ScreenManager
。
duration¶
Duration in seconds of the transition.
过渡的持续时间(秒)。
duration is a NumericProperty and defaults to .4 (= 400ms).duration
是一个NumericProperty
,默认值为.4(即400毫秒)。
Changed in version 1.8.0: Default duration has been changed from 700ms to 400ms.
在版本1.8.0中更改:默认持续时间已从700毫秒更改为400毫秒。
is_active¶
Indicate whether the transition is currently active or not.
指示过渡当前是否处于活动状态。
is_active is a BooleanProperty and defaults to False, read-only.is_active
是一个BooleanProperty
,默认为False
,且是只读的。
manager¶
ScreenManager object, set when the screen is added to a manager.ScreenManager
对象,当屏幕被添加到管理器时设置。
manager is an ObjectProperty and defaults to None, read-only.manager
是一个ObjectProperty
,默认值为None
,且是只读的。
remove_screen(screen)¶
(internal) Used to remove a screen from the ScreenManager.
(内部使用)用于从ScreenManager
中移除一个屏幕。
screen_in¶
Property that contains the screen to show. Automatically set by the ScreenManager.
包含要显示的屏幕的属性。自动由ScreenManager
设置。
screen_in is an ObjectProperty and defaults to None.screen_in
是一个ObjectProperty
,默认值为None
。
screen_out¶
Property that contains the screen to hide. Automatically set by the ScreenManager.
包含要隐藏的屏幕的属性。自动由ScreenManager
设置。
screen_out is an ObjectProperty and defaults to None.screen_out
是一个 ObjectProperty
,默认值为 None
。
start(manager)¶
(internal) Starts the transition. This is automatically called by the ScreenManager.
(内部使用)开始过渡。这会被ScreenManager
自动调用。
stop()¶
(internal) Stops the transition. This is automatically called by the ScreenManager.
(内部使用)停止过渡。这会被ScreenManager
自动调用。
class kivy.uix.screenmanager.WipeTransition¶
Bases: kivy.uix.screenmanager.ShaderTransition
Wipe transition, based on a fragment Shader. 基于片段着色器的擦除过渡(Wipe Transition)。
fs¶
Fragment shader to use. 要使用的片段着色器。
fs is a StringProperty and defaults to None. fs
是一个 StringProperty
,默认值为 None
。