繁体   English   中英

Kivy AttributeError: object 没有属性

[英]Kivy AttributeError: object has no attribute

我正在尝试向我的应用程序添加一个屏幕来拍照,但单击捕获按钮时我不断收到此错误: AttributeError: 'AddPhotoScreen' object has no attribute 'capture'

这是我的 kivy 和 main.py 文件:

<AddPhotoScreen>:
    name: "addphoto"
    FloatLayout:
        Camera:
            id: camera
            resolution: (1280, 800)
            play: True

        GridLayout:
            cols: 1
            rows: 2
            spacing: 1
            pos_hint: {"center_x":.5, "center_y":.1}
            MDIconButton:
                icon: "camera"
                user_font_size: "64sp"
                text_color: 0,0,0,0.9
                pos_hint: {"center_x":.5, "center_y":.5}
                on_press: root.capture()
            MDIconButton:
                icon: "keyboard-backspace"
                user_font_size: "64sp"
                text_color: 0,0,0,0.9
                pos_hint: {"center_x":.5, "center_y":.5}
                on_release:app.root.current = "nouvelele"```



Main.py file

class AddPhotoScreen(Screen):
    def build(self):
        return CameraClick()
        
class CameraClick(BoxLayout):
    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 ("Photo Added")

我猜这个问题是因为on_press: root.capture()但我不明白,因为class AddPhotoScreen正在返回CameraClick 此代码几乎完全是从 kivy 示例库中复制/粘贴的,因此它应该可以工作。

错误消息清楚地说明了错误。 您的AddPhotoScreen没有名为capture的方法。 从其他方法返回对这一事实没有影响。 您需要在AddPhotoScreen中实现capture()方法。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM