[英]Error with kivy app on Linux
I am learning kivy and have installed kivy on my Lubuntu as well as windows. 我正在学习kivy,并在Lubuntu和Windows上安装了kivy。 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.
我编写了一个名为TextApp的试用版应用程序,该应用程序可以在Windows 10上完美运行。但是在Lubuntu中运行相同的代码时会引发错误。 The files are as under:-
这些文件如下:
` `
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()`
BoxLayout: 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 : 这段代码可以在Windows上完美运行,但是会在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.
请有人帮我。
kv文件名应该是小写的,它可以在Windows上使用,因为Windows在文件名中不区分大小写,您可以将文件重命名为textapp.kv
(或text.kv
),它应该可以工作。
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' eg TextApp -> text.kv 由于您未使用Kivy Builder加载字符串或文件,因此按照名称约定,Kivy将以与小写字母相同的名称查找与您的App类同名的Kv文件,如果以'App'结尾的话则减去“ App”,例如TextApp- > 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()
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.