Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from plyer import camera
- from kivy.app import App
- from kivy.uix.button import Button
- from kivy.uix.camera import Camera
- from kivy.uix.boxlayout import BoxLayout
- class CameraApp(App):
- def build(self):
- # create a layout
- layout = BoxLayout()
- # create a camera widget
- cam = Camera(index=0, resolution=(640,480))
- # create a button that will take a picture
- button = Button(text='Take Picture')
- # bind the button's on_press event to a callback function
- button.bind(on_press=self.take_picture)
- # add the camera and the button to the layout
- layout.add_widget(cam)
- layout.add_widget(button)
- return layout
- def take_picture(self, *args):
- # use plyer.camera.take_picture to take a picture
- # pass a filename where to save the picture
- # pass a callback function that will be called after taking picture
- camera.take_picture(filename='my_picture.jpg', on_complete=self.picture_taken)
- def picture_taken(self, obj):
- # this function will be called after taking picture
- # obj is either the filename where picture was saved or None if error occurred
- if obj:
- print('Picture saved at ' + obj)
- else:
- print('Error taking picture')
- # run the app
- CameraApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement