无法在kivy中切换屏幕

时间:2015-09-08 08:33:36

标签: python kivy

我有下面的文件我试图切换到新窗口一旦按下主屏幕上的按钮但它会抛出错误'没有屏幕的名称"验证屏幕"'

我调试了一下并复制粘贴屏幕:部分从verifyscreen.kv到我们的homescreen.kv文件,它开始工作。

但是为什么它甚至无法获得屏幕我只能启动两个kv文件?

homescreen.kv

<HomeScreen>:
    orientation: 'vertical'
    screen_manager: screen_manager
    ScreenManager:
        size_hint: 1, 1
        id: screen_manager
        Screen:
            BoxLayout:
                orientation: 'vertical'
                name: 'Home_Screen'
                id: 'home'
                Label: 
                    markup: True
                    text: 'Home-Panel'
                Button:
                    text: 'submitt'
                    size_hint: 1,1
                    id: submitt
                    pos_hint: {'center_x': .5}
                    on_press:
                        root.verify()

verifyscreen.kv

<VerifyScreen>:
    orientation: 'vertical'
    verify_screen_manager: verify_screen_manager
    ScreenManager:
        size_hint: 1, 1
        id: verify_screen_manager
        Screen:
            name: 'VerifyScreen'
            id: verify_screen

main.py

#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-

from functools import partial
import os
import random
import kivy
kivy.require('1.8.0')
#all required modules are imported 
from kivy.uix.screenmanager import Screen
from kivy.uix.screenmanager import ScreenManager


slides = [ "HomeScreen","VerifyScreen" ]

for slide in slides:
    kv_file = "{}.kv".format(slide.lower())
    Builder.load_file(os.path.join("slides", kv_file))


class HomeScreen(Screen):
    screen_manager = ObjectProperty(None)
    verify_screen_manager = ObjectProperty(None)
    verify_screen = ObjectProperty(None)
    def __init__(self, **kwargs):
        super(HomeScreen, self).__init__(**kwargs)
        self.orientation = 'vertical'

    def verify(self):
        print "manish"
        #self.screen_manager.current = 'VerifyScreen'
        self.screen_manager.switch_to(self.verify_screen)

class HomeScreenApp(App):
    def build(self):
        return HomeScreen()


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

0 个答案:

没有答案