Home > Mobile >  Kivy No Screen with name
Kivy No Screen with name

Time:08-25

In my main.py:

class WelcomeScreen(Screen):
    pass

class SignupScreen(Screen):
    username = ObjectProperty(None)
    
    def submit(self):
        db.add_user(self.username.text) 
        self.reset()
        self.root.current = "login"
    
    def login(self):
        self.reset()
        self.current = "signup"
    
    def reset(self):
        self.username.text = ""
        
class LoginScreen(Screen):
    pass

class WindowManager(ScreenManager):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        Clock.schedule_once(self.screen_switch_signup, 2)

    def screen_switch_signup(self, time):
        self.current = 'signup'
        
db = DataBase()

class mainApp(App):
    kv_directory = 'kv'
    
    def build(self):
        return WindowManager()

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

Then,my main.kv:

#:import SlideTransition kivy.uix.screenmanager.SlideTransition

WindowManager:
    name: "screen_manager"
    transition: SlideTransition()
    WelcomeScreen:
        name: "welcome"
        #: include kv/signupScreen.kv
        manager: 'screen_manager'
    SignupScreen:
        name: "signup"
        #: include kv/signupScreen.kv
        manager: 'screen_manager'
    LoginScreen:
        name: "login"
        #: include kv/loginScreen.kv
        manager: 'screen_manager'

Finally, I have 3 kv files:

My signupScreen.kv

<SignupScreen>:
    username: username

    TextInput:
        id: username  
        hint_text: "Username"

    Button:
        text: "SIGN UP"
        on_release:            
            app.root.transition.direction = "right"
            root.submit()

my loginScreen.kv

<LoginScreen>:
    BoxLayout:
        orientation: 'vertical'
        Label:
            id: email
            text: "Your email"
        Button
            id: go_back_screen_1
            text: 'Go back'
            on_release: 
                app.root.current = 'signup'
                root.manager.transition.direction = 'right'

And finally the welcomeScreen.kv

<WelcomeScreen>:
    Label:
        text: "Welcome"

When I launch, I get the error:


File "kivy_clock.pyx", line 218, in kivy._clock.ClockEvent.tick File "\Git\main.py", line 89, in screen_switch_signup self.current = 'signup' kivy.uix.screenmanager.ScreenManagerException: No Screen with name "signup".

I'm pretty new to Kivy, so I don't understand what's happening here.

The architecture is like that:

* myApp
   * main.py
   * kv
      * main.kv
      * loginScreen.kv
      * signupScreen.kv
      * welcomeScreen.kv

Any one knows please?

CodePudding user response:

I have found several moments that can raise the error:

  1. Here kv_directory = 'kv' you tell where all of your kv files are located. It means there should be a directory kv in your project directory. Make sure you have this directory and all kv files in it.
  2. You should use <WindowManager>: instead of WindowManager: in your main.kv because you want to define (discribe) WindowManager class but not to add it to your app.

These hints should fix your app

Edit: I didn't catch sight of you've added the architecture of your project. Then just do the second point

  • Related