Linux上的kivy应用程序出错

时间:2017-09-04 09:27:51

标签: python kivy

我正在学习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

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()

此代码在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__'
>>> 

我无法破译它。请有人帮助我。

2 个答案:

答案 0 :(得分:0)

kv文件名应该是小写的,它适用于Windows,因为Windows不会区分文件名中的大写和小写,您可以将文件重命名为textapp.kv(或text.kv),以及它应该工作。

答案 1 :(得分:0)

由于您没有使用Kivy Builder加载字符串或文件,因此按名称惯例,Kivy会查找与 App类 同名的Kv文件小写,减去&#34; App&#34;如果以“应用程序”结尾例如 TextApp - &gt;的 text.kv

text.kv

sed -i -e "s/FILENAME_LOGIN/'login.php'/g" /your/file

main.py

Private Sub CommandButton1_Click()
Dim IE As New InternetExplorer
Dim oW As Worksheet: Set oW = ThisWorkbook.Worksheets("Sheet1")
Dim oEleCol As MSHTML.IHTMLElementCollection
Dim oEle As MSHTML.IHTMLElement


With IE
'Set IE = CreateObject("InternetExplorer.Application")

    ' Set IE
    .Visible = True
    'ShowWindow .hwnd, SW_SHOWMAXIMIZED

    ' Navigate to URL
    .Navigate "https://www.nseindia.com/products/content/equities/equities/eq_security.htm"

    ' Wait for page to be ready
    While .Busy
      DoEvents  'wait until IE is done loading page.
    Wend

    ' Set criteria
    .document.all("symbol").Value = oW.Range("B1")
    .document.all("series").Value = oW.Range("B2")
    .document.getElementById("rdDateToDate").Click

    ' Wait for page to be ready
    While .Busy
      DoEvents  'wait until IE is done loading page.
    Wend

    ' Set remaining criteria
    .document.all("fromDate").Value = oW.Range("B3")
    .document.all("toDate").Value = oW.Range("D3")

    ' Submit criteria
    .document.getElementById("submitMe").Click

    ' Wait for page to be ready
    While .Busy
      DoEvents  'wait until IE is done loading page.
    Wend

    ' Find the link to download file
    Set oEleCol = .document.getElementsByTagName("A")
    For Each oEle In oEleCol
        If oEle.innerHTML = "Download file in csv format" Then
            oEleCol.Click
            Exit For
        End If
    Next

    ' Wait for page to be ready
    While .Busy
      DoEvents  'wait until IE is done loading page.
    Wend

End With

End Sub

输出

enter image description here