程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Kivy AttributeError: 'super' 对象没有属性 '__getattr__'(尝试了所有以前的解决方案)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Kivy AttributeError: 'super' 对象没有属性 '__getattr__'(尝试了所有以前的解决方案)?

开发过程中遇到Kivy AttributeError: 'super' 对象没有属性 '__getattr__'(尝试了所有以前的解决方案)的问题如何解决?下面主要结合日常开发的经验,给出你关于Kivy AttributeError: 'super' 对象没有属性 '__getattr__'(尝试了所有以前的解决方案)的解决方法建议,希望对你解决Kivy AttributeError: 'super' 对象没有属性 '__getattr__'(尝试了所有以前的解决方案)有所启发或帮助;

这是 Python 中最烦人的错误之一,根据问题有很多解决方案

我的文件

@H_769_7@main.py

# imports
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen,ScreenManager


# Defining Screen,ScreenManager And App Classes:
class MainScreen(Screen):
    pass


class ShortCuts(Screen):
    pass


class WindowManager(ScreenManager):
    pass


# Kivy Lang Builder Packed As A Variable
BLD = Builder.load_file("KV_file.kv")


class OnlineClassmacros(App):

    # Initializing The App
    def __init__(self,**kwargs):
        super(OnlineClassmacros,self).__init__(**kwargs)

    # Defining The App By Referencing The Packed Kivy.Lang.builder Variable Created At The Start Of The .py file
    def build(self):
        return BLD

    @staticmethod
    def Get():
        query = BLD.IDs.SearchENGIne.text

        print(query)


# Todo: Monetize The >>Online Class Macros<< Application By Using KivMob


# MainLooPing The Application Using  [if __name__ == "__main__":]
if __name__ == "__main__":
    OnlineClassmacros().run()

KV_file.kv

# imporTing Our Function.py As A Python ModulE into Kivy-Lang\

#######################################################
#:import redirect Function.redirect
#######################################################

# Pre-Styling Widgets
<Label>
    halign: 'center'
    valign: 'center'
    BACkground_color: '0','.4','.3','.4'
<button>
    halign: 'center'
    valign: 'center'
    BACkground_color: "0",".1",".8"

# Configuring The Screens and the Screen Manager
WindowManager:
    MainScreen:
    ShortCuts:

# Building All The Classes In Our "Main.py" file

<MainScreen>:
    name: "MainScreen"

    canvas.before:
        Rectangle:
            size: self.size
            pos: self.pos
            source: "Images/BACkground 2.png"
    BoxLayout:
        orIEntation: "horizontal"
        BoxLayout:
            size_hint: .2,1
            orIEntation: "vertical"
            button:
                text: "Google\nDocs"
                on_release: redirect("https://www.docs.Google.com")
            button:
                text: "Google\nSlIDes"
                on_release:
                    redirect("https://slIDes.Google.com/u/0/h")
            button:
                text: "Gmail"
                on_release:
                    redirect("https://www.gmail.com")
            button:
                text: "Google\nClassroom"
                on_release:
                    redirect("https://classroom.Google.com/u/0/")
        BoxLayout:
            size_hint: .6,1
            BoxLayout:
                orIEntation: "vertical"
                TexTinput:
                    size_hint: 1,.2
                    multiline: True
                    hint_text: "Search here"
                    BACkground_color: 1,1,.78
                    ID: SearchENGIne
                GrIDLayout:
                    cols: 3
                    button:
                        text: "Google Scholar\nSearch"

                    button:
                        text: "Wikipedia\nSearch"
                        on_release:
                            app.Get()
                    button:
                        text: "Google\nSearch"
                    button:
                        text: "RefSeek\nSearch"
                    button:
                        text: "Microsoft Academic\nSearch"
                    button:
                        text: "Hyper Search"
                        BACkground_color: 1,.99
        BoxLayout:
            size_hint: .2,1
            orIEntation: "vertical"
            button:
                text: "Google\nspreadSheets"
                on_release:
                    redirect("https://classroom.Google.com/u/0/h")
            button:
                text: "MicroSoft\nTeams"
                on_release:
                    redirect("https://classroom.Google.com/u/0/h")
            button:
                text: "OutLook"
                on_release:
                    redirect("https://classroom.Google.com/u/0/h")



<ShortCuts>:
    canvas.before:
        Rectangle:
            pos: self.pos
            size: self.pos
            source: 'Images/ BACkground 3.png'

错误:

C:\Users\mayan\ApPDAta\Local\Programs\Python\python39\python.exe "C:/Online Class Macros ;)/Main.py"
[INFO   ] [Logger      ] Record log in C:\Users\mayan\.kivy\logs\kivy_21-06-13_7.txt
[INFO   ] [deps        ] successfully imported "kivy_deps.gstreamer" 0.3.2
[INFO   ] [deps        ] successfully imported "kivy_deps.angle" 0.3.0
[INFO   ] [deps        ] successfully imported "kivy_deps.glew" 0.3.0
[INFO   ] [deps        ] successfully imported "kivy_deps.sdl2" 0.3.1
[INFO   ] [Kivy        ] v2.0.0
[INFO   ] [Kivy        ] Installed at "C:\Users\mayan\ApPDAta\Local\Programs\Python\python39\lib\site-packages\kivy\__init__.py"
[INFO   ] [Python      ] v3.9.4 (tags/v3.9.4:1f2e308,Apr  6 2021,13:40:21) [MSC v.1928 64 bit (AMD64)]
[INFO   ] [Python      ] Interpreter at "C:\Users\mayan\ApPDAta\Local\Programs\Python\python39\python.exe"
[INFO   ] [Factory     ] 186 symbols loaded
[INFO   ] [Image       ] ProvIDers: img_tex,img_dds,img_sdl2,img_pil (img_ffpyplayer ignored)
[INFO   ] [Window      ] ProvIDer: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] GLEW initialization succeeded
[INFO   ] [GL          ] BACkend used <glew>
[INFO   ] [GL          ] OpenGL version <b'4.0.0 - Build 10.18.10.5059'>
[INFO   ] [GL          ] OpenGL vendor <b'Intel'>
[INFO   ] [GL          ] OpenGL renderer <b'Intel(R) HD Graphics'>
[INFO   ] [GL          ] OpenGL parsed version: 4,0
[INFO   ] [GL          ] Shading version <b'4.00 - Build 10.18.10.5059'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <16>
[INFO   ] [Window      ] auto add sdl2 input provIDer
[INFO   ] [Window      ] virtual keyboard not allowed,single mode,not docked
[INFO   ] [GL          ] NPOT texture support is available
[INFO   ] [GL          ] Unpack subimage support is available
[INFO   ] [Text        ] ProvIDer: sdl2
[INFO   ] [Base        ] Start application main loop
[INFO   ] [Base        ] Leaving application in progress...
 TraceBACk (most recent call last):
   file "kivy\propertIEs.pyx",line 861,in kivy.propertIEs.ObservableDict.__getattr__
 KeyError: 'SearchENGIne'
 
 During handling of the above exception,another exception occurred:
 
 TraceBACk (most recent call last):
   file "C:\Online Class Macros ;)\Main.py",line 46,in <module>
     OnlineClassmacros().run()
   file "C:\Users\mayan\ApPDAta\Local\Programs\Python\python39\lib\site-packages\kivy\app.py",line 950,in run
     runtouchApp()
   file "C:\Users\mayan\ApPDAta\Local\Programs\Python\python39\lib\site-packages\kivy\base.py",line 582,in runtouchApp
     EventLoop.mainloop()
   file "C:\Users\mayan\ApPDAta\Local\Programs\Python\python39\lib\site-packages\kivy\base.py",line 347,in mainloop
     self.IDle()
   file "C:\Users\mayan\ApPDAta\Local\Programs\Python\python39\lib\site-packages\kivy\base.py",line 391,in IDle
     self.dispatch_input()
   file "C:\Users\mayan\ApPDAta\Local\Programs\Python\python39\lib\site-packages\kivy\base.py",line 342,in dispatch_input
     post_dispatch_input(*pop(0))
   file "C:\Users\mayan\ApPDAta\Local\Programs\Python\python39\lib\site-packages\kivy\base.py",line 308,in post_dispatch_input
     wID.dispatch('on_touch_up',mE)
   file "kivy\_event.pyx",line 709,in kivy._event.Eventdispatcher.dispatch
   file "C:\Users\mayan\ApPDAta\Local\Programs\Python\python39\lib\site-packages\kivy\uix\behaviors\button.py",line 179,in on_touch_up
     self.dispatch('on_release')
   file "kivy\_event.pyx",line 705,in kivy._event.Eventdispatcher.dispatch
   file "kivy\_event.pyx",line 1248,in kivy._event.EventObservers.dispatch
   file "kivy\_event.pyx",line 1132,in kivy._event.EventObservers._dispatch
   file "C:\Users\mayan\ApPDAta\Local\Programs\Python\python39\lib\site-packages\kivy\lang\builder.py",line 57,in custom_callBACk
     exec(__kvlang__.co_value,IDmap)
   file "C:\Online Class Macros ;)\KV_file.kv",line 70,in <module>
     app.Get()
   file "C:\Online Class Macros ;)\Main.py",line 36,in Get
     query = BLD.IDs.SearchENGIne.text
   file "kivy\propertIEs.pyx",line 864,in kivy.propertIEs.ObservableDict.__getattr__
 AttributeError: 'super' object has no attribute '__getattr__'

Process finished with exit code 1

这个错误以前发生在我身上,我解决了它,但正如我所说,答案取决于问题。 如果没有人删除我的问题说它是重复的,我真的很感激。

解决方法

神秘的错误消息没有多大帮助,但堆栈跟踪显示错误发生在该行中:

query = BLD.ids.SearchENGIne.text

此行失败的原因是您试图访问 id 对象中不存在的 SearchENGIne (BLD)。 BLD 对象是您的 kv 的根,也就是 WindowManager,但 SearchENGIne id 是在 <MainScreen>: 规则中定义的。因此,修复方法是通过正确的对象访问该 ID:

def Get():
    app = App.get_running_app()  # get a refrence to the running App
    main_screen = app.root.get_screen('MainScreen')  # get a reference to the MainScreen
    query = main_screen.ids.SearchENGIne.text  # now use the id

    print(query)

请注意,documentation 表示:

当 kv 文件被处理时,weakrefs 到所有标记为 id 被添加到根小部件的 id 字典中。

该文档不正确。 ids 实际上是添加到包含 id 的规则的基础对象中,而不是添加到 kv 文件的根小部件中。

大佬总结

以上是大佬教程为你收集整理的Kivy AttributeError: 'super' 对象没有属性 '__getattr__'(尝试了所有以前的解决方案)全部内容,希望文章能够帮你解决Kivy AttributeError: 'super' 对象没有属性 '__getattr__'(尝试了所有以前的解决方案)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。