简体   繁体   English

Kivy - 过渡之间的黑屏

[英]Kivy - Black Screen between transitions

I'm trying to copy this gif , which is done in Kivy (here's the link to the full page )我正在尝试复制这个gif ,这是在 Kivy 中完成的(这里是完整页面的链接

Just as I started, I noticed a black screen between transition ( link to what it looks like so you don't have to copy-paste and run)刚开始时,我注意到转换之间出现黑屏(链接到它的外观,因此您不必复制粘贴并运行)

Why does that black screen appear?为什么会出现那个黑屏?

EDIT: I must work without buttons.编辑:我必须在没有按钮的情况下工作。

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>:
    canvas.before:
        Color:
            rgba: 122,255,0,2
        Rectangle:
            pos: self.pos
            size: self.size
    Label:
        text: 'hello'


<SettingsScreen>:
    canvas.before:
        Color:
            rgba: 0,255,0,2
        Rectangle:
            pos: self.pos
            size: self.size
    Label:
        text: 'hello'
""")

# Declare both screens
class MenuScreen(Screen):
    def on_touch_down(self, touch):
        sm.current = 'settings'

class SettingsScreen(Screen):
    def on_touch_down(self, touch):
        sm.current = 'menu'

# Create the screen manager
sm = ScreenManager()
sm.add_widget(MenuScreen(name='menu'))
sm.add_widget(SettingsScreen(name='settings'))

class TestApp(App):

    def build(self):
        return sm

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

EDIT: I've tried this but still not working编辑:我试过这个,但仍然无法正常工作

<sm>:
    canvas:
        Color:
            rgb: (0, 255, 255)
        Rectangle:
            size: self.size
            pos: self.pos

You are not supposed to use the Screen subclasses directly.您不应该直接使用 Screen 子类。 Instead you must add a component first (eg Button or Layout), for example use RelativeLayout :相反,您必须先添加一个组件(例如按钮或布局),例如使用RelativeLayout

Builder.load_string("""
<MenuScreen>:
    RelativeLayout:
        canvas.before:
            Color:
                rgba: 122,255,0,2
            Rectangle:
                pos: self.pos
                size: self.size
        Label:
            text: 'hello'


<SettingsScreen>:
    RelativeLayout:
        canvas.before:
            Color:
                rgba: 0,255,0,2
            Rectangle:
                pos: self.pos
                size: self.size
        Label:
            text: 'hello'
""")

That black area is a canvas of the screen manager.那个黑色区域是屏幕管理器的画布。 If you don't like it black, then you can paint it, just like you did with screens;如果你不喜欢黑色,那么你可以把它画出来,就像你画屏风一样; or change transition type to NoTransition to hide it.或将过渡类型更改为NoTransition以隐藏它。

Also, you should consider building your screen manager inside that kv lang string.此外,您应该考虑在该 kv lang 字符串中构建您的屏幕管理器。

Old, but in case anyone runs into this issue:旧的,但万一有人遇到这个问题:

To clarify the vague responses in the comments, you need to paint your screen manager the same way you would paint a screen.为了澄清评论中含糊不清的回答,您需要以与绘制屏幕相同的方式绘制屏幕管理器。

Example in kvlang: kvlang 中的示例:

ScreenManagement:
    canvas.before:
        Color:
            rgba: 1,1,1,1
        Rectangle:
            size: self.size
            pos: self.pos
    id: screen_manager
    transition: NoTransition()
    Screen1:
    Screen2:
    Settings_:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM