0

This Has To One OF The Most Annoying Errors In Python That Have So Many Solutions Depending On The Question

My Files

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", ".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,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,0,0,.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'

Error:

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

This error has happened to me before and I solved it but as I said the answer is question-dependent. I Would Really Appreciate it If No One Delete My Question Saying It's a Duplicate.

Crypto
  • 337
  • 3
  • 11

1 Answers1

1

The cryptic error message is of little help, but the stack trace shows that the error occurs in the line:

query = BLD.ids.SearchEngine.text

The reason that this line fails is that you are trying to access an id (SearchEngine) that does not exist in the BLD object. The BLD object is the root of your kv, which is the WindowManager, but the SearchEngine id is defined in the <MainScreen>: rule. So the fix is to access that id through the correct object:

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)

Note that the documentation says:

When the kv file is processed, weakrefs to all the widgets tagged with ids are added to the root widget’s ids dictionary.

That documentation is incorrect. The ids are actually added to the base object of the rule that contains the id, not to the root widget of the kv file.

John Anderson
  • 35,991
  • 4
  • 13
  • 36