python - Kivy - 转换之间的黑屏

标签 python kivy

我正在尝试复制此gif ,这是在 Kivy 中完成的(这是整页的 link)

就在我开始的时候,我注意到转换之间有一个黑屏(link到它看起来的样子,所以你不必复制粘贴并运行)

为什么会出现黑屏?

编辑:我必须在没有按钮的情况下工作。

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()

编辑:我已经尝试过,但仍然不起作用

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

最佳答案

您不应该直接使用 Screen 子类。相反,您必须首先添加一个组件(例如按钮或布局),例如使用 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'
""")

关于python - Kivy - 转换之间的黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39724267/

相关文章:

android - Python 2.7 urllib.urlretrieve 未知的 url 类型 https

python - FileChooser 的字体颜色

scrollview - 设置 kivy scrollview effects_cls 属性的正确方法是什么?

Python:从终端运行此代码

python - 目录存在时 Shutil.copy IO Error2

python - 如何在python上使用sagemath?

python - 在 0's and 1' 的矩阵中查找路径

python - Kivy 安装出错了 - Windows 10(正在运行,现在不是在 gstreamer 之后)

android - 安卓版基维

python - 匹配2个不同的数据帧返回值然后进行比较