kivy : TypeError: 'NoneType' object is not subscriptable

kivy : TypeError: 'NoneType' object is not subscriptable

我的代码可以用了!但我不知道为什么会出现此错误! 谁能知道我该如何解决? :( 我认为错误是关于我的代码之间的 space,但我无法修复它。

这是我的代码:

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.lang import Builder
from kivy.properties import ObjectProperty
from kivy.uix.screenmanager import ScreenManager , Screen
from kivy.uix.image import Image
from kivy.core.window import Window
from kivy.base import runTouchApp
from kivymd.app import MDApp
from kivy.uix.boxlayout import BoxLayout
import time
from kivy.core.window import Window
from kivy.uix.camera import Camera 

Window.size = (1600, 850)



class MainPage(Screen):
    pass

class AboutBtn(Screen):
    pass

class WindowManager(ScreenManager):
    pass

class CameraClick(Screen):
    def capture(self):
        camera = self.ids['camera']
        timestr = time.strftime("%Y%m%d_%H%M%S")
        camera.export_to_png("IMG_{}.png".format(timestr))
        print("Captured")

     
class ResizableDraggablePicture(Screen):
    def on_touch_down(self, touch):
        if touch.is_mouse_scrolling:
            if touch.button == 'scrolldown':
                if self.scale < 10:
                    self.scale = self.scale * 1.1
            elif touch.button == 'scrollup':
                if self.scale > 1:
                    self.scale = self.scale * 0.8

            

Builder.load_string("""

#:import utils kivy.utils
<WindowManager>:
    MainPage:
    CameraClick:
    ResizableDraggablePicture:
    AboutBtn:
    
    
<ResizableDraggablePicture>:
    name: "resizableDraggablePicture"
    
    
<RoundedButton@Button>:
    background_color:(0,0,0,0)
    bachground_normal: ""
    canvas.before:
        Color:
            rgba:(195/255.0,231/255.0,247/255.0,1)
        RoundedRectangle:
            size: self.size
            pos: self.pos
            radius: [35]     


<MainPage>:
    name: "main page"

    Image:
        source: 'images/MICC.png'
        allow_stretch: True
        keep_ratio: False
        
    BoxLayout:
        cols:1
        orientation: "horizontal"
        size: root.width , root.height
        spacing: 25
        padding: 80, 900 , 1300 , 250


        RoundedButton:
            text: "about"
            color: (200,250,210)
            pos_hint : {'center_x': 0.5}
            font_size: 50
            size_hint_x: 1
            height:40
            size_hint_y: None
            width:30
            on_release: app.root.current = "aboutBtn"

#             Image:
#                 source: 'images/information.png'
#                 height:40
#                 width:40
#                 center_x: 210
#                 center_y: self.parent.center_y
                
    BoxLayout:
        cols:1
        orientation: "horizontal"
        size: root.width , root.height
        spacing: 25
        padding: 530, 900 , 900 , 260

        RoundedButton:
            text: "take a picture"
            color: (200,250,210)
            font_size: 40
            size_hint_x: 1
            height:60
            size_hint_y: None
            width:500
            on_release: app.root.current = "camera"

#             Image:
#                 source: 'images/takePic.png'
#                 height:40
#                 width:40
#                 center_x: 500
#                 center_y: self.parent.center_y


    BoxLayout:
        cols:1
        orientation: "horizontal"
        size: root.width , root.height
        spacing: 25
        padding: 1200, 600, 50 , 220
#         
#         RoundedButton:
#             text: "Setting"
#             font_size: 50
#             size_hint_x: 1
#             height:60
#             size_hint_y: None
#             width:500
#             # on_release: app.root.current = "SettingBtn"

            Image:
                source: 'images/settings.png'
                height:40
                width:40
                center_x: 830
                center_y: self.parent.center_y
                
<AboutBtn>:
    name: "aboutBtn"

    Image:
        source: 'images/aboutBtn.png'
        allow_stretch: True
        keep_ratio: False    
            
            
    BoxLayout:
        orientation: 'vertical'
        padding: 90 , 800 , 1400 , 750
        spacing: 5   

        ToggleButton:
            text: 'HOME'
            on_release: app.root.current = "main page"
            size_hint_y: None
            height: '48dp'            
                
                
                
                
<CameraClick>:

    name: "camera"
    orientation: 'vertical'    
 
    Image:
        source: 'images/bck-g.png'
        allow_stretch: True
        keep_ratio: False

            

            
            
    Camera:
        id: camera
        play: True
        allow_stretch: True
    
    
    BoxLayout:
        orientation: 'vertical'
        padding: 50 , 50 , 50 , 50
        spacing: 5   

        ToggleButton:
            text: 'Play'
            on_press: camera.play = not camera.play
            size_hint_y: None
            height: '48dp'
        Button:
            text: 'Capture'
            size_hint_y: None
            height: '48dp'
            on_press: root.capture()
            
            
    BoxLayout:
        orientation: 'vertical'
        padding: 50 , 10 , 800 , 600
    

        ToggleButton:
            text: 'ZOOM'
            size_hint_y: None
            size_hint_x: None
            height: '48dp'
            pos:200,200
            font_size:12
            width: 100
            height: 50
            on_release: app.root.current = "resizableDraggablePicture"
            
            
            
    BoxLayout:
        orientation: 'vertical'
        padding: 50 , 10 , 800 , 700
    

        ToggleButton:
            text: 'HOME'
            size_hint_y: None
            size_hint_x: None
            height: '48dp'
            pos:200,200
            font_size:12
            width: 100
            height: 50
            on_release: app.root.current = "main page"               

""")

class Shenacell(MDApp):
    def build(self):
        # self.theme_cls.theme_style = "Dark"
        self.theme_cls.primary_palette = "BlueGray"
        return WindowManager()

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

我以前从未见过这个错误,所以我不知道它是什么意思。 我想我在代码中使用“spaces”时遇到问题。但我想不通。 –

这是错误:

[INFO   ] [deps        ] Successfully imported "kivy_deps.gstreamer" 0.3.2
[INFO   ] [deps        ] Successfully imported "kivy_deps.angle" 0.3.0
[INFO   ] [deps        ] Successfully imported "kivy_deps.glew" 0.3.0
[INFO   ] [deps        ] Successfully imported "kivy_deps.sdl2" 0.3.1
[INFO   ] [Python      ] v3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)]
[INFO   ] [Factory     ] 186 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [Window      ] Activate GLES2/ANGLE context
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] Backend used <angle_sdl2>
[INFO   ] [GL          ] OpenGL version <b'OpenGL ES 3.0.0 (ANGLE 2.1.13739 git hash: 385fb40fd460)'>
[INFO   ] [GL          ] OpenGL vendor <b'Google Inc.'>
[INFO   ] [GL          ] OpenGL renderer <b'ANGLE (Intel(R) UHD Graphics 620 Direct3D11 vs_5_0 ps_5_0)'>
[INFO   ] [GL          ] OpenGL parsed version: 3, 0
[INFO   ] [GL          ] Shading version <b'OpenGL ES GLSL ES 3.00 (ANGLE 2.1.13739 git hash: 385fb40fd460)'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <16>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [KivyMD      ] v0.104.1
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [GL          ] NPOT texture support is available
[INFO   ] [Camera      ] Provider: opencv(['camera_picamera', 'camera_gi'] ignored)
 Traceback (most recent call last):
   File "a.py", line 48, in <module>
     Builder.load_string("""

     if current_property[:3] == 'on_':
 TypeError: 'NoneType' object is not subscriptable

你的kv部分:

    Image:
        source: 'images/settings.png'
        height:40
        width:40
        center_x: 830
        center_y: self.parent.center_y

缩进不正确。