【发布时间】:2017-09-04 09:27:50
【问题描述】:
我正在学习 kivy,并在我的 Lubuntu 和 windows 上安装了 kivy。 我已经编写了一个名为 TextApp 的试用应用程序,它可以在 Windows 10 上完美运行。但是当我在 Lubuntu 中运行相同的代码时会抛出错误。 文件如下:-
文件 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 文件 TextApp.kv
文件 TextApp.kv
框布局:
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()
此代码在 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__'
>>>
我无法破译它。请有人帮助我。
【问题讨论】: