I am building an app that will use a kivy camera to take pictures of text and runs it through OCR. My when I build by python and kivy file I cannot figure out how to separate them into different files in order to continue the app process.
I got this code from CodersHubb which works but I would like to break it out with Kivy language so I can add screens in the app.
from kivy.app import App
from kivy.uix.camera import Camera
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.core.window import Window
Window.size = (500, 550)
class cameraApp(App):
def build(self):
global cam
cam = Camera()
btn = Button(text="Capture Total")
btn.size_hint = (.1, .1)
btn.font_size = 35
btn.background_color = 'blue'
btn.bind(on_press = self.capture_image)
layout = GridLayout(rows=2, cols=1)
layout.add_widget(cam)
layout.add_widget(btn)
return layout
def capture_image(self, *args):
global cam
cam.export_to_png('image.png')
print('Image captured and saved in current working directory')
if __name__ == '__main__':
cameraApp().run()
you just want to write all the stuff in a *.kv file? try this: *.kv file:
GridLayout:
rows:2
cols:1
Camera:
id:camera
Button:
text:"Capture Total"
size_hint: (.1,.1)
font_size:35
background_color:"blue"
on_press:app.capture_image
main.py file:
from kivy.app import App
from kivy.lang.builder import Builder
from kivy.core.window import Window
Window.size = (500, 550)
class cameraApp(App):
def build(self):
self.root = Builder.load_file("MY_KV.kv")
return self.root
def capture_image(self, *args):
cam = self.root.ids.camera
cam.export_to_png('image.png')
print('Image captured and saved in current working directory')
if __name__ == '__main__':
cameraApp().run()
don't forget to change filename in build
function to your kv file