简体   繁体   English

屏幕管理器(AttributeError:“ super”对象没有属性“ __getattr__”)

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

I am fairly new to Kivy programming and need to use it for this project. 我对Kivy编程相当陌生,需要在项目中使用它。 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 ' AttributeError:'super'对象没有属性' 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 ` .Kv文件

 #: 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. 表示kivy_screen_manager不是ids一部分,这些id存储在字典中。

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. 只能通过id来访问Login的子级,如果摘要中看到.kv,我们将显示以下内容,并且显然kivy_screen_manager不在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: 如果要从屏幕访问ScreenManager ,则必须使用manager属性,在这种情况下,它会发生变化:

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. 问题在于,root用户是Login,而不是ScreenManager ,并且在root之上没有任何内容,因此即使您已声明ScreenManager也不存在。

Assuming that the .kv file is called design.kv the following parts must be modified: 假设.kv文件名为design.kv则必须修改以下部分:

design.kv design.kv

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

...

and load the .kv with Builder: 并使用Builder加载.kv:

from kivy.lang import Builder

....

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

...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 屏幕管理器AttributeError:“超级”对象没有属性“ __getattr__” - Screen manager AttributeError: 'super' object has no attribute '__getattr__' AttributeError:“超级”对象没有属性“ __getattr__” - AttributeError: 'super' object has no attribute '__getattr__' AttributeError:“超级”对象没有属性“ __getattr __”(我进行了搜索,但无济于事) - AttributeError: 'super' object has no attribute '__getattr__' ( I searched, but to no avail) AttributeError: &#39;super&#39; 对象在 python 中没有属性 &#39;__getattr__&#39; - AttributeError: 'super' object has no attribute '__getattr__' in python Kivy: AttributeError: 'super' object 没有属性 '__getattr__' - Kivy: AttributeError: 'super' object has no attribute '__getattr__' Kivy AttributeError: 'super' object 没有属性 '__getattr__' - Kivy AttributeError: 'super' object has no attribute '__getattr__' Kivy AttributeError: 'super' object has no attribute '__getattr__' 错误 - Kivy AttributeError: 'super' object has no attribute '__getattr__' error Python Kivy 返回 'AttributeError: 'super' object 没有属性 '__getattr__'' - Python Kivy returning 'AttributeError: 'super' object has no attribute '__getattr__'' KIVY 错误:AttributeError:&#39;super&#39; 对象没有属性 &#39;__getattr__&#39; - KIVY ERROR: AttributeError: 'super' object has no attribute '__getattr__' python kivy AttributeError:“超级”对象没有属性“ __getattr__” - python kivy AttributeError: 'super' object has no attribute '__getattr__'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM