首页 > 解决方案 > python kivy“发生异常:AssertionError”

问题描述

我得到的错误是

发生异常:AssertionError <kivy.uix.button.Button object at 0x7fa5d1309e40> is not callable File "/home/derek/Documents/programs/SBAPga/SBAPgraphicsCardAcellerated.py", line 34, init self.submit.bind(on_press =self.submit) 文件“/home/derek/Documents/programs/SBAPga/SBAPgraphicsCardAcellerated.py”,第 47 行,在构建中返回 gridlayout() 文件“/home/derek/Documents/programs/SBAPga/SBAPgraphicsCardAcellerated.py”,第 50 行,在 SBAP().run()

我的代码如下

from kivy import *
from kivy.app import *
from kivy.core.spelling import *
from kivy.core.window import *
from kivy.lang.builder import *
from kivy.properties import *
from kivy.uix.colorpicker import *
from kivy.uix.gridlayout import *
from kivy.uix.scrollview import *
from kivy.uix.textinput import *
from kivy.uix.widget import *
from kivy.uix.button import *
from kivy.uix.label import *

label="Source Text"

class gridlayout(GridLayout):
    def __init__(self, **kwargs):
        super(gridlayout, self).__init__(**kwargs)
        self.cols = 1


        self.inside = GridLayout()
        self.inside.cols = 2

        self.inside.add_widget(Label(text=label))
        self.SourceText = TextInput(multiline=True)
        self.inside.add_widget(self.SourceText)
        self.cols = 1

        self.submit = Button(text="Submit")
        self.submit.bind(on_press=self.submit)
        
        self.add_widget(self.inside)

        self.add_widget(self.submit)

def Pressed(self,instance):
    #  SourceText = self.SourceText.text
    #  label = SourceText
    print("SourceText")
    
class SBAP(App):
    def build(self):
        return gridlayout()

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

控制台输出是

/SBAPgraphicsCardAcellerated.py
[INFO   ] [Logger      ] Record log in /home/derek/.kivy/logs/kivy_21-11-14_53.txt
[INFO   ] [Kivy        ] v2.0.0
[INFO   ] [Kivy        ] Installed at "/usr/lib/python3/dist-packages/kivy/__init__.py"
[INFO   ] [Python      ] v3.8.10 (default, Sep 28 2021, 16:10:42) 
[GCC 9.3.0]
[INFO   ] [Python      ] Interpreter at "/usr/bin/python3"
[INFO   ] [Factory     ] 186 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)
[CRITICAL] [Spelling    ] Unable to find any valuable Spelling provider. Please enable debug logging (e.g. add -d if running from the command line, or change the log level in the config) and re-run your app to identify potential causes
enchant - ModuleNotFoundError: No module named 'enchant'
  File "/usr/lib/python3/dist-packages/kivy/core/__init__.py", line 58, in core_select_lib
    mod = __import__(name='{2}.{0}.{1}'.format(
  File "/usr/lib/python3/dist-packages/kivy/core/spelling/spelling_enchant.py", line 12, in <module>
    import enchant

[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] Backend used <sdl2>
[INFO   ] [GL          ] OpenGL version <b'4.6 (Compatibility Profile) Mesa 21.0.3'>
[INFO   ] [GL          ] OpenGL vendor <b'AMD'>
[INFO   ] [GL          ] OpenGL renderer <b'AMD Radeon(TM) Vega 11 Graphics (RAVEN, DRM 3.40.0, 5.11.0-40-generic, LLVM 12.0.0)'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 6
[INFO   ] [GL          ] Shading version <b'4.60'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Clipboard   ] Provider: xclip
[INFO   ] [CutBuffer   ] cut buffer support enabled
 Traceback (most recent call last):
   File "/home/derek/Documents/programs/SBAPga/SBAPgraphicsCardAcellerated.py", line 50, in <module>
     SBAP().run()
   File "/usr/lib/python3/dist-packages/kivy/app.py", line 949, in run
     self._run_prepare()
   File "/usr/lib/python3/dist-packages/kivy/app.py", line 919, in _run_prepare
     root = self.build()
   File "/home/derek/Documents/programs/SBAPga/SBAPgraphicsCardAcellerated.py", line 47, in build
     return gridlayout()
   File "/home/derek/Documents/programs/SBAPga/SBAPgraphicsCardAcellerated.py", line 34, in __init__
     self.submit.bind(on_press=self.submit)
   File "kivy/_event.pyx", line 421, in kivy._event.EventDispatcher.bind
 AssertionError: <kivy.uix.button.Button object at 0x7f5adc04d5f0> is not callable

标签: pythonpython-3.xkivykivy-language

解决方案


推荐阅读