简体   繁体   中英

screen manager (AttributeError: 'super' object has no attribute '__getattr__')

I am fairly new to Kivy programming and need to use it for this project. The problem I am having is that I keep getting the following error whenever I try to use a screen manager to change screens.

AttributeError: 'super' object has no attribute ' getattr '

If anybody could explain how to fix the error, but also explain what causes it? Any help is greatly appriciated

Main Code: `

  import kivy
import webbrowser
import MSQLHandler
kivy.require('1.10.0')


from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Label
from kivy.uix.widget import Widget
from kivy.uix.listview import ListItemButton
from kivy.properties import ObjectProperty
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, CardTransition

class Login(Screen):

    class kivy_screen_manager(ScreenManager):
        pass

    teacher_connect_image = ObjectProperty()

    username_text_input = ObjectProperty()
    password_text_input = ObjectProperty()

    def LoginButton(self):
        MSQLHandler.LoginSystem(self.username_text_input.text, self.password_text_input.text, 0)

    def changeScreen(self,  next_screen):
        self.manager.current = next_screen


class MainKivyFrameApp(App):

    def build(self):
        return Login()

mainFrame = MainKivyFrameApp()
mainFrame.run()

`

The .Kv File `

 #: import main NewProject
#: import CardTransition kivy.uix.screenmanager.CardTransition

ScreenManager:
    Login:
        id: kivy_screen_manager
        name: "Login"
    LogedInScreen:
        id: LogedInScreen
        name: "LogedInScreen"



<Login@Screen>:
    id: kivy_screen_manager
    name: "Login"
    teacher_connect_image: logo_image
    username_text_input: username
    password_text_input: password
    teahcerId_text_input: teacherId
    name: "LoginMain"

    BoxLayout:
        padding: 10
        spacing: 10
        orientation: "vertical"
        Image:
            source: 'ApplicationMainLogo.png'
            id: logo_image

        Label:
            text: "Teacher ID"
        TextInput:
            font_size: root.height / 20
            id: teacherId

        Label:
            text: "Username"
        TextInput:
            font_size: root.height / 20
            id: username

        Label:
            text: "Password"
        TextInput:
            font_size: root.height / 20
            id: password

        Button:
            text: "Login"
            on_release: app.root.changeScreen("LogedInScreen")




<LogedInScreen@Screen>:
    id: LogedInScreen
    name: "LogedInScreen"
    padding: 10
    spacing: 10
    orientation: "vertical"

    Button:
        text: "Back Home?"

`

Full Error message:

    Traceback (most recent call last):
   File "C:/Users/XOmar/Desktop/MMSA - Multi Media School Access/NewProject.py", line 39, in <module>
     mainFrame.run()
   File "C:\Users\XOmar\Desktop\MMSA - Multi Media School Access\venv\lib\site-packages\kivy\app.py", line 801, in run
     self.load_kv(filename=self.kv_file)
   File "C:\Users\XOmar\Desktop\MMSA - Multi Media School Access\venv\lib\site-packages\kivy\app.py", line 598, in load_kv
     root = Builder.load_file(rfilename)
   File "C:\Users\XOmar\Desktop\MMSA - Multi Media School Access\venv\lib\site-packages\kivy\lang\builder.py", line 301, in load_file
     return self.load_string(data, **kwargs)
   File "C:\Users\XOmar\Desktop\MMSA - Multi Media School Access\venv\lib\site-packages\kivy\lang\builder.py", line 350, in load_string
     parser = Parser(content=string, filename=fn)
   File "C:\Users\XOmar\Desktop\MMSA - Multi Media School Access\venv\lib\site-packages\kivy\lang\parser.py", line 392, in __init__
     self.parse(content)
   File "C:\Users\XOmar\Desktop\MMSA - Multi Media School Access\venv\lib\site-packages\kivy\lang\parser.py", line 498, in parse
     self.execute_directives()
   File "C:\Users\XOmar\Desktop\MMSA - Multi Media School Access\venv\lib\site-packages\kivy\lang\parser.py", line 462, in execute_directives
     mod = __import__(package)
   File "C:\Users\XOmar\Desktop\MMSA - Multi Media School Access\NewProject.py", line 39, in <module>
     mainFrame.run()
   File "C:\Users\XOmar\Desktop\MMSA - Multi Media School Access\venv\lib\site-packages\kivy\app.py", line 828, in run
     runTouchApp()
   File "C:\Users\XOmar\Desktop\MMSA - Multi Media School Access\venv\lib\site-packages\kivy\base.py", line 504, in runTouchApp
     EventLoop.window.mainloop()
   File "C:\Users\XOmar\Desktop\MMSA - Multi Media School Access\venv\lib\site-packages\kivy\core\window\window_sdl2.py", line 663, in mainloop
     self._mainloop()
   File "C:\Users\XOmar\Desktop\MMSA - Multi Media School Access\venv\lib\site-packages\kivy\core\window\window_sdl2.py", line 405, in _mainloop
     EventLoop.idle()
   File "C:\Users\XOmar\Desktop\MMSA - Multi Media School Access\venv\lib\site-packages\kivy\base.py", line 342, in idle
     self.dispatch_input()
   File "C:\Users\XOmar\Desktop\MMSA - Multi Media School Access\venv\lib\site-packages\kivy\base.py", line 327, in dispatch_input
     post_dispatch_input(*pop(0))
   File "C:\Users\XOmar\Desktop\MMSA - Multi Media School Access\venv\lib\site-packages\kivy\base.py", line 293, in post_dispatch_input
     wid.dispatch('on_touch_up', me)
   File "kivy\_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (kivy\_event.c:8191)
   File "C:\Users\XOmar\Desktop\MMSA - Multi Media School Access\venv\lib\site-packages\kivy\uix\behaviors\button.py", line 179, in on_touch_up
     self.dispatch('on_release')
   File "kivy\_event.pyx", line 714, in kivy._event.EventDispatcher.dispatch (kivy\_event.c:8146)
   File "kivy\_event.pyx", line 1225, in kivy._event.EventObservers.dispatch (kivy\_event.c:14035)
   File "kivy\_event.pyx", line 1109, in kivy._event.EventObservers._dispatch (kivy\_event.c:12816)
   File "C:\Users\XOmar\Desktop\MMSA - Multi Media School Access\venv\lib\site-packages\kivy\lang\builder.py", line 64, in custom_callback
     exec(__kvlang__.co_value, idmap)
   File "C:\Users\XOmar\Desktop\MMSA - Multi Media School Access\mainkivyframe.kv", line 51, in <module>
     on_release: app.root.changeScreen("LogedInScreen")
   File "C:\Users\XOmar\Desktop\MMSA - Multi Media School Access\NewProject.py", line 30, in changeScreen
     self.manager.current = next_screen
 AttributeError: 'NoneType' object has no attribute 'current'

'

The error message is accurate:

Traceback (most recent call last):
   File "kivy\properties.pyx", line 836, in kivy.properties.ObservableDict.__getattr__ (kivy\properties.c:12509)
 KeyError: 'kivy_screen_manager'

Indicates that kivy_screen_manager is not part of ids , the ids are stored inside a dictionary.

Only the children of Login can be accessed by id, and if we see the .kv in summary we have the following and clearly kivy_screen_manager is not under Login.

<Login@Screen>:
    ...
    name: "LoginMain"

    BoxLayout:
        ...
        Label:
            ...
        TextInput:
            ...
            id: teacherId
        Label:
            ...
        TextInput:
            ...
            id: username
        Label:
            ...
        TextInput:
            ...
            id: password
        Button:
            ...

If you want to access the ScreenManager from a screen you must use the manager attribute, in your case it changes:

self.ids.kivy_screen_manager.current = "LogedInScreen" 

to

self.manager.current = "LogedInScreen"

Update:

The problem is that to root is Login, and not the ScreenManager , and above the root there is nothing, so the ScreenManager does not exist even if you have declared it.

Assuming that the .kv file is called design.kv the following parts must be modified:

design.kv

....
<Login@Screen>:
    ...
        Button:
            text: "Login"
            on_release: root.changeScreen("LogedInScreen")

...

and load the .kv with Builder:

from kivy.lang import Builder

....

class MainKivyFrameApp(App):
    def build(self):
        root = Builder.load_file("design.kv")
        return root

...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM