diff --git a/examples/camera/main.py b/examples/camera/main.py index 505abec3d..f7671e92e 100644 --- a/examples/camera/main.py +++ b/examples/camera/main.py @@ -16,9 +16,10 @@ throw an exception during the kv language processing. from kivy.app import App from kivy.lang import Builder - -kv = ''' -BoxLayout: +from kivy.uix.boxlayout import BoxLayout +import time +Builder.load_string(''' +: orientation: 'vertical' Camera: id: camera @@ -29,12 +30,30 @@ BoxLayout: 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() +''') + + +class CameraClick(BoxLayout): + def capture(self): + ''' + Function to capture the images and give them the names + according to their captured time and date. + ''' + camera = self.ids['camera'] + timestr = time.strftime("%Y%m%d_%H%M%S") + camera.export_to_png("IMG_" + timestr) + print("Captured") class TestCamera(App): + def build(self): - return Builder.load_string(kv) + return CameraClick() TestCamera().run()