'Kivy ScreenManager error: kivy.uix.screenmanager.ScreenManagerException: No Screen with name "homepage"

I am building an app using kivy. I have set up a screen manager in my app and defined two pages. On a button press in the first page, the display should switch to the second page. But, the function can't seem to find the homepage screen that I've already defined in the screen manager. When the connect_button button is pressed in the LoginPage, I get an error (I've titled this post with the error I have gotten.) Here is my python code:

from kivy.app import App
import SpartanGrid
from kivy.core.window import Window
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
import kivy 
kivy.require('1.0.6')
from kivy.uix.textinput import TextInput
from kivy.graphics import *

class LoginPage(GridLayout, Screen):
    def __init__(self, **kwargs):
        super(LoginPage, self).__init__()
        self.cols=2
        self.padding=[50,50,50,50]

        login = TextInput(hint_text="Enter your username")
        self.add_widget(login)
        connect_button = Button(
            text="Login")
        connect_button.bind(on_press = self.homeScreen)
        self.add_widget(connect_button)

    def homeScreen(self,*args):
        self.manager.current = 'homepage'

class ScreenManagement(ScreenManager):
    def __init__(self, **kwargs):
        super(ScreenManagement, self).__init__(**kwargs)

class SpartanApp(App):
    def build(self):
        Window.clearcolor = (0.82, 0.9, 0.93, 1)
        sm = ScreenManagement(transition=NoTransition())
        sm.add_widget(LoginPage(name='login'))
        sm.add_widget(SpartanGrid.SpartanGrid(name='homepage'))
        return sm
        # return LoginPage()

Here is what the top of my homepage screen looks like. You can see that I've set it up to be a screen with a grid layout. It is located in a separate py file.

class SpartanGrid(GridLayout, Screen):

    def __init__(self, **kwargs):

        super(SpartanGrid, self).__init__()
        self.cols=1
        self.padding=[50,50,50,50]

We are not using a kv file at all. Any help would be appreciated!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source