简体   繁体   English

Linux上的Kivy App错误

[英]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:- 这些文件如下:

File main.py 文件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 奇异果文件TextApp.kv

File TextApp.kv 文件TextApp.kv

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

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 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 输出量

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 虚拟环境中出现异常,窗口提供程序错误(Linux) - kivy in virtual environment, window provider error (linux) 在manjaro linux中从pip安装kivy时出错 - Error in installing kivy from pip in manjaro linux 在 ubntu linux 中调试 kivy 应用程序时出现问题,当我尝试调试该应用程序时,它开始导入需求,然后显示错误并退出 - Problem debugging kivy app in ubntu linux, when i tried to debug the app it started import requirements and then showd the error and exited 从kivy.app导入应用程序错误,但导入kivy正在工作 - from kivy.app import App error but import kivy is working Kivy-尝试将Firebase与我的Kivy应用程序集成吗? 杰森错误 - Kivy - Trying to integrate firebase with my kivy app? Json Error Kivy/Python Countdown App 项目 kivy has no attribute &#39;built&#39; 错误 - Kivy/Python Countdown App project kivy has no attribute 'built' error 如何在Linux上打包Kivy IOS应用程序? - How can I package a Kivy IOS app while on linux? 使用 kivy 和 bluepy 将 python3 应用程序从 Linux 移植到 Android - porting a python3 app from Linux to Android using kivy and bluepy Kivy:带有错误Gstplayer Playbin的打包应用 - Kivy: package app with error gstplayer playbin 为Android商店签名Kivy应用时出错 - Error while signing an kivy app for the android store
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM