How do I display an image in my pwd?
import kivy
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.image import Image
class MyApp(App):
def build(self):
return Image('b1.png')
MyApp().run()
Basically, set your image file name under source attribute under "Image" in kivy. kv (file). Remember to set a clock schedule once as above and you can make your modification of your photo. You can even add some photo looping (dynamically) by changing the clock scheduler to Clock.
You can check the Image documentation to see that the image source is controlled by the source
property. Therefore you should be able to change just one line to make it work:
return Image(source='b1.png')
The acceptable result for me is too comprehensive and simple.
I have a better way of doing it using .kv file:
Kivy.kv (file)
<main_display>:
BoxLayout:
orientation: "vertical"
Image:
id: imageView
source: '<random_name>.jpg'
allow_stretch: True
....
Kivy.py (file)
class main_display(BoxLayout):
def __init__(self, **kwargs):
super(main_display,self).__init__()
# Photo can be reference by running the photo function once:
Clock.schedule_once(self.photo)
def photo(self,dt):
# Replace the given image source value:
self.ids.imageView.source = 'kivy_test.jpg'
Clock.schedule_interval(self.photo, 0.06)
.I have try to directly assign the attribute 'source' from kivy.py (file) but failed with assertion error.
ENJOY and please do comment if you're not clear !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With