0

I've been searching for the solution of this problem over the all internet but I still can't find the right solution. There are lots of generic answers but none of those have solved my problem..

I am trying to build a simple CLOCK app with kivy and python 3.6.4 but every time I run the main.py I get this error:

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

MY MAIN "main.py" FILE IS THIS:

 from kivy.app import App

 from kivy.clock import Clock

 from kivy.core.text import LabelBase

 from kivy.core.window import Window

 from kivy.utils import get_color_from_hex

 from time import strftime


 class ClockApp(App):

    def on_start(self):
        Clock.schedule_interval(self.update, 0)

    def update(self, nap):

        self.root.ids.time.text = strftime('[b]%H[/b]:%M:%S')


 if __name__ == '__main__':
     Window.clearcolor = get_color_from_hex('#101216')
     LabelBase.register(name='Roboto',
                        fn_regular='Roboto-Thin.ttf',
                        fn_bold='Roboto-Medium.ttf')
     ClockApp().run() 

MY "clock.kv" FILE IS THIS:

 <Label>:
     font_name: 'Roboto'
     font_size: 60
     markup: True

 BoxLayout:
     orientation: 'vertical'

 Label:
     id: time
     text: '[b]00[/b]:00:00'

THIS IS THE ERROR THAT APPEARS WHEN I RUN THE "main.py"

[INFO   ] [Logger      ] Record log in C:\Users\Alessandro\.kivy \logs\kivy_18-05-19_4.txt
[INFO   ] [Kivy        ] v1.10.0
[INFO   ] [Python      ] v3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)]
[INFO   ] [Factory     ] 194 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [OSC         ] using <thread> for socket
[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.4.0 - Build 20.19.15.4549'>
[INFO   ] [GL          ] OpenGL vendor <b'Intel'>
[INFO   ] [GL          ] OpenGL renderer <b'Intel(R) HD Graphics 5500'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 4
[INFO   ] [GL          ] Shading version <b'4.40 - Build 20.19.15.4549'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Shader      ] fragment shader: <b"WARNING: 0:7: '' :  #version directive missing">
[INFO   ] [Shader      ] vertex shader: <b"WARNING: 0:7: '' :  #version directive missing">
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [Base        ] Start application main loop
[INFO   ] [Base        ] Leaving application in progress...
     Traceback (most recent call last):
       File "kivy\properties.pyx", line 836, in kivy.properties.ObservableDict.__getattr__ (kivy\properties.c:12509)
 KeyError: 'time'

 During handling of the above exception, another exception occurred:
  Traceback (most recent call last):
   File "C:\Users\Alessandro\Desktop\Clock\main.py", line 24, in <module>
     ClockApp().run()
   File "C:\Users\Alessandro\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\app.py", line 828, in run
     runTouchApp()
   File "C:\Users\Alessandro\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\base.py", line 504, in runTouchApp
     EventLoop.window.mainloop()
   File "C:\Users\Alessandro\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\window\window_sdl2.py", line 663, in mainloop
     self._mainloop()
   File "C:\Users\Alessandro\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\core\window\window_sdl2.py", line 405, in _mainloop
     EventLoop.idle()
    File "C:\Users\Alessandro\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\base.py", line 339, in idle
     Clock.tick()
   File "C:\Users\Alessandro\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\clock.py", line 581, in tick
     self._process_events()
   File "kivy\_clock.pyx", line 367, in kivy._clock.CyClockBase._process_events (kivy\_clock.c:7700)
   File "kivy\_clock.pyx", line 397, in kivy._clock.CyClockBase._process_events (kivy\_clock.c:7577)
   File "kivy\_clock.pyx", line 395, in kivy._clock.CyClockBase._process_events (kivy\_clock.c:7498)
   File "kivy\_clock.pyx", line 167, in kivy._clock.ClockEvent.tick (kivy\_clock.c:3490)
   File "C:\Users\Alessandro\Desktop\Clock\main.py", line 16, in update
     self.root.ids.time.text = strftime('[b]%H[/b]:%M:%S')
   File "kivy\properties.pyx", line 839, in kivy.properties.ObservableDict.__getattr__ (kivy\properties.c:12654)
 AttributeError: 'super' object has no attribute '__getattr__'
mx0
  • 6,445
  • 12
  • 49
  • 54
Alex
  • 3
  • 2

1 Answers1

0

The structure of your .kv does not look correct, for example it is observed that there are many roots that would cause you another problem, so if you want a response that tells you the reason for your problem you should improve your indentation.

Instead I'll show you a correct .kv where the root will be the BoxLayout and your child the Label with id time:

clock.kv

<Label>:
    font_name: 'Roboto'
    font_size: 60
    markup: True

BoxLayout:
    orientation: 'vertical'

    Label:
        id: time
        text: '[b]00[/b]:00:00'

main.py

from kivy.app import App
from kivy.clock import Clock
from kivy.core.text import LabelBase
from kivy.core.window import Window
from kivy.utils import get_color_from_hex
from time import strftime


class ClockApp(App):
    def on_start(self):
        Clock.schedule_interval(self.update, 0)

    def update(self, *args):
        self.root.ids.time.text = strftime('[b]%H[/b]:%M:%S')

if __name__ == '__main__':
    Window.clearcolor = get_color_from_hex('#101216')
    LabelBase.register(name='Roboto', fn_regular='Roboto-Thin.ttf', fn_bold='Roboto-Medium.ttf')
    ClockApp().run() 

enter image description here

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Thank you eyllanesc! Now I know how to correctly build a .kv file. I have modified both the kv file and the main file but unfortunately i still get the same error as before. What could be the reason? I also noticed that if I modify "" def update(self, *args): "" in "" def update_time(self, *args): """ i get a different error: """ AttributeError: 'ClockApp' object has no attribute 'update' """ and I don't get the same error as before. Could you please help please? Thanks a lot – Alex May 19 '18 at 14:30
  • @Alex Have you copied exactly the code that I have shown ?, I see that you do not take much into account the indentations, in python it is very important. Share your files through github, drive, dropbox etc. also indicate me the version of Python, Kivy and if you are using some IDE. – eyllanesc May 19 '18 at 14:34
  • @Alex if you change `def update(self, *args)` to `def update_time(self, *args)` you must also change `Clock.schedule_interval (self.update, 0)` to `Clock.schedule_interval(self.update_time, 0)` – eyllanesc May 19 '18 at 14:35
  • Thanks eyllanesc! In this picture I show you everything: https://ibb.co/kyFELo In a "Clock" folder on the desktop, i have the two files: "clock.kv" and "main", both on python 3.6.4. I have written them on pyhton IDLE 3.6 32 Bit. I have installed kivy 2 weeks ago using the instructions showed on the official site. Thanks for your help – Alex May 20 '18 at 00:06
  • Ok, this is the folder: https://drive.google.com/drive/folders/1tE1YNx0Gt8go_3qqTwRQzgyMOky_AxtY?usp=sharing – Alex May 20 '18 at 00:27
  • @Alex change `clock.kv.py` to `clock.kv` – eyllanesc May 20 '18 at 05:28
  • @Alex If you review well the image that you show in the following link https://ibb.co/kyFELo you will see that the .kv extension has .py, so I recommend you change it, for that it enables the visibility of the extensions. – eyllanesc May 20 '18 at 05:33
  • Now it works!!! THANK YOU VERY MUCH!!! Bye eyllanesc, wish you the best – Alex May 20 '18 at 09:10