Reputation: 46969
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()
Upvotes: 16
Views: 31791
Reputation: 202
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 !
Upvotes: 4
Reputation: 29488
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')
Upvotes: 18