Python kivy:TypeError:';非类型';对象不可下标
我的代码是工作!但我不知道为什么我会犯这个错误! 有人知道我该怎么修吗( 我认为错误是关于代码之间的空间,但我无法修复它 这是我的代码:Python kivy:TypeError:';非类型';对象不可下标,python,python-3.x,raspberry-pi,kivy,raspberry-pi4,Python,Python 3.x,Raspberry Pi,Kivy,Raspberry Pi4,我的代码是工作!但我不知道为什么我会犯这个错误! 有人知道我该怎么修吗( 我认为错误是关于代码之间的空间,但我无法修复它 这是我的代码: 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
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()
从kivy.app导入应用
从kivy.uix.widget导入widget
从kivy.lang导入生成器
从kivy.properties导入ObjectProperty
从kivy.uix.screenmanager导入screenmanager,屏幕
从kivy.uix.image导入图像
从kivy.core.window导入窗口
从kivy.base导入runTouchApp
从kivymd.app导入MDApp
从kivy.uix.boxlayout导入boxlayout
导入时间
从kivy.core.window导入窗口
从kivy.uix.camera导入摄影机
Window.size=(1600850)
类主页(屏幕):
通过
关于TBTN的课程(屏幕):
通过
类WindowManager(屏幕管理器):
通过
类CameraClick(屏幕):
def捕获(自我):
camera=self.ids['camera']
timestr=time.strftime(“%Y%m%d\u%H%m%S”)
camera.export_to_png(“IMG_{}.png.format(timestr))
打印(“捕获”)
类大小可调整的RaggablePicture(屏幕):
def on_触控向下(自身,触控):
如果touch.is\u鼠标\u滚动:
如果touch.button==“向下滚动”:
如果自评量表<10:
self.scale=self.scale*1.1
elif touch.button=='scrollup':
如果self.scale>1:
self.scale=self.scale*0.8
生成器。加载\u字符串(“”)
#:导入utils kivy.utils
:
主页:
摄影机单击:
调整大小的碎布图片:
约TBTN:
:
名称:“ResizebleDraggablePicture”
:
背景颜色:(0,0,0,0)
Bachu正常值:“
在以下情况之前:
颜色:
rgba:(195/255.0231/255.0247/255.0,1)
圆反射角:
大小:self.size
pos:self.pos
半径:[35]
:
名称:“主页”
图片:
来源:“images/MICC.png”
允许拉伸:真
保留比率:False
盒子布局:
科尔斯:1
方向:“水平”
尺寸:根.宽度,根.高度
间距:25
填充:809001300250
圆形按钮:
正文:“关于”
颜色:(200250210)
位置提示:{'center_x':0.5}
字体大小:50
大小提示:1
身高:40
尺寸提示:无
宽度:30
发布时:app.root.current=“aboutBtn”
#图片:
#来源:“images/information.png”
#身高:40
#宽度:40
#中心x:210
#中心y:self.parent.center
盒子布局:
科尔斯:1
方向:“水平”
尺寸:根.宽度,根.高度
间距:25
填充:530900900260
圆形按钮:
文字:“拍照”
颜色:(200250210)
字体大小:40
大小提示:1
身高:60
尺寸提示:无
宽度:500
发布时:app.root.current=“摄像头”
#图片:
#来源:“images/takePic.png”
#身高:40
#宽度:40
#中心x:500
#中心y:self.parent.center
盒子布局:
科尔斯:1
方向:“水平”
尺寸:根.宽度,根.高度
间距:25
填充:1200、600、50、220
#
#圆形按钮:
#文本:“设置”
#字体大小:50
#大小提示:1
#身高:60
#尺寸提示:无
#宽度:500
##发布时:app.root.current=“SettingBtn”
图片:
来源:“images/settings.png”
身高:40
宽度:40
中环x:830
中心y:self.parent.center
:
名称:“大约”
图片:
来源:“images/aboutBtn.png”
允许拉伸:真
保留比率:False
盒子布局:
方向:“垂直”
填充:908001400750
间距:5
切换按钮:
文字:“家”
发布时:app.root.current=“主页”
尺寸提示:无
高度:“48dp”
:
名称:“照相机”
方向:“垂直”
图片:
来源:“images/bck-g.png”
允许拉伸:真
保留比率:False
摄像机:
id:照相机
剧本:真的
允许拉伸:真
盒子布局:
方向:“垂直”
填充:50,50,50,50
间距:5
切换按钮:
文字:“播放”
按:camera.play=不按camera.play
尺寸提示:无
高度:“48dp”
按钮:
文本:“捕获”
尺寸提示:无
高度:“48dp”
on_press:root.capture()
盒子布局:
方向:“垂直”
填充:50,1080600
切换按钮:
文本:“缩放”
尺寸提示:无
大小提示:无
高度:“48dp”
位置:200200
字体大小:12
宽度:100
身高:50
发布时:app.root.current=“resizebledraggablepicture”
盒子布局:
方向:“垂直”
填充:50、10、800、700
切换按钮:
文字:“家”
尺寸提示:无
大小提示:无
高度:“48dp”
位置:200200
字体大小:12
宽度:100
身高:50
发布时:app.root.curren
[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
Image:
source: 'images/settings.png'
height:40
width:40
center_x: 830
center_y: self.parent.center_y