当我尝试设置屏幕导航时,它会产生空白屏幕,没有错误。 我的方法是执行我写的每一行 我期待标签和图像 谁能指出这段代码有什么问题。任何帮助将不胜感激
这是我的代码 主要.py
import kivy
from kivy.config import Config
Config.set('graphics', 'width', '400')
Config.set('graphics', 'height', '500')
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.screenmanager import ScreenManager,Screen
kv = Builder.load_file("outer.kv")
class Firstwindow(Screen):
pass
class Secondwindow(Screen):
pass
class Thirdwindow(Screen):
pass
class WindowManager(ScreenManager):
def screen_manager_method(self):
print('Hello from screen manager')
class CrashCourse(App):
def build(self):
return kv
if __name__ == '__main__':
CrashCourse().run()
outer.kv
ScreenManager:
id: screen_manager
<Firstwindow>:
name: "home_screen"
id: home_screen
Label:
text:"Enter your name bellow"
Image:
source:"down.jpg"
<Secondwindow>:
name: "menu_screen"
id: menu_screen
<Thirdwindow>:
name: "game_screen"
id: game_screen
尝试使用 pytoileur 加载文件
pip install pytoileur
from pytoileur import Build kv = Build.load("outer.kv")
执行时:
kv = Builder.load_file("outer.kv")
Builder
创建一个 ScreenManager
并将其返回为 kv
。 kv
文件的其他部分导致规则被加载。这些规则描述了如何构建 Screens
,但它们并不构建 Screens
。尝试更换:
ScreenManager:
id: screen_manager
与:
ScreenManager:
id: screen_manager
Firstwindow:
Secondwindow:
Thirdwindow:
这应该会产生一个
ScreenManager
和三个 Screens
。