Rashid
Rashid

Reputation: 25

Error with kivy app on Linux

I am learning kivy and have installed kivy on my Lubuntu as well as windows. I ahve written a trial App named TextApp which runs perfectly on Windows 10. But throws error when I run the same code in Lubuntu. The files are as under:-

File main.py

`

import kivy
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty

class TextApp(App):
    def on_start(self):
        self.root.ids.mytext.text = 'You can Change it'

    def TextChange(self):
        self.root.ids.mytext.text = 'Text Changes'

if __name__ == '__main__':
    TextApp().run()`
    
    

kivy file TextApp.kv

File TextApp.kv

BoxLayout:

orientation: 'vertical'
Label:
    id: mytext
    text ='A'
    font_size = 30

BoxLayout:
    height:150
    orientation: 'horizontal'
    padding: 20
    spacing: 30
    size_hint:(1,None)

    Button:
        id: mybutton
        text: 'CLICK'
        font_size:25
        on_press: app.TextChange()
    Button:
        id: mybutton2
        text: 'Back'
        font_size:25
        on_press: app.on_start()
    
    

This code run perfectly in Windows, but throw following error on Lubuntu :

Python 3.5.2+ (default, Sep 22 2016, 12:18:14) 
[GCC 6.2.0 20160927] on linux
Type "copyright", "credits" or "license()" for more information.
>>> 
================== RESTART: /home/rashid/Documents/main.py ==================
[INFO   ] [Logger      ] Record log in /home/rashid/.kivy/logs/kivy_17-09-04_16.txt
[INFO   ] [Kivy        ] v1.10.0
[INFO   ] [Python      ] v3.5.2+ (default, Sep 22 2016, 12:18:14) 
[GCC 6.2.0 20160927]
[INFO   ] [Factory     ] 194 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO   ] [OSC         ] using <multiprocessing> for socket
[INFO   ] [Window      ] Provider: sdl2(['window_egl_rpi'] ignored)
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] Backend used <gl>
[INFO   ] [GL          ] OpenGL version <b'3.0 Mesa 12.0.6'>
[INFO   ] [GL          ] OpenGL vendor <b'VMware, Inc.'>
[INFO   ] [GL          ] OpenGL renderer <b'Gallium 0.4 on llvmpipe (LLVM 3.8, 256 bits)'>
[INFO   ] [GL          ] OpenGL parsed version: 3, 0
[INFO   ] [GL          ] Shading version <b'1.30'>
[INFO   ] [GL          ] Texture max size <8192>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
 Traceback (most recent call last):
   File "kivy/properties.pyx", line 836, in kivy.properties.ObservableDict.__getattr__ (kivy/properties.c:11859)
 KeyError: 'mytext'
 
 During handling of the above exception, another exception occurred:
 
 Traceback (most recent call last):
   File "/home/rashid/Documents/main.py", line 15, in <module>
     TextApp().run()
   File "/usr/lib/python3/dist-packages/kivy/app.py", line 827, in run
     self.dispatch('on_start')
   File "kivy/_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:7807)
   File "/home/rashid/Documents/main.py", line 9, in on_start
     self.root.ids.mytext.text = 'You can Change it'
   File "kivy/properties.pyx", line 839, in kivy.properties.ObservableDict.__getattr__ (kivy/properties.c:11966)
 AttributeError: 'super' object has no attribute '__getattr__'
>>> 

I am unable to decipher it . Please some one help me.

Upvotes: 1

Views: 786

Answers (2)

ikolim
ikolim

Reputation: 16001

Since you are not using Kivy Builder to load a string or a file, by name convention, Kivy looks for a Kv file with the same name as your App class in lowercase, minus "App" if it ends with 'App' e.g. TextApp -> text.kv

text.kv

#:kivy 1.10.0

BoxLayout:
    orientation: 'vertical'
    Label:
        id: mytext
        text: 'A'
        font_size: 30

    BoxLayout:
        height:150
        orientation: 'horizontal'
        padding: 20
        spacing: 30
        size_hint:(1,None)

        Button:
            id: mybutton
            text: 'CLICK'
            font_size:25
            on_press: app.TextChange()
        Button:
            id: mybutton2
            text: 'Back'
            font_size:25
            on_press: app.on_start()

main.py

from kivy.app import App


class TextApp(App):
    def on_start(self):
        self.root.ids.mytext.text = 'You can Change it'

    def TextChange(self):
        self.root.ids.mytext.text = 'Text Changes'

if __name__ == '__main__':
    TextApp().run()

Output

enter image description here

Upvotes: 0

Tshirtman
Tshirtman

Reputation: 5949

The kv filename is supposed to be lowercase, it works on windows because windows doesn't differenciate between uppercase and lowercase in filenames, you can rename the file to textapp.kv (or text.kv), and it should work.

Upvotes: 1

Related Questions