Skip to content Skip to sidebar Skip to footer

How Can I Reload A Image In Kivy Python

this is my script ... 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 Imag

Solution 1:

you can use reload() the read the image from the disk again this will reload even if the original data of the image is updated or changed

self.ids.image1.source = './Images/file.png'self.ids.image1.reload()

Solution 2:

Make your own widget class, and make the image an attribute, so you can reference it. Then use clock to schedule an interval method, to constantly reload the image. In the example below, the update_pic method is executed once every second.

import kivy
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.image import Image
from kivy.clock import Clock
from kivy.uix.widget import Widget


classMyImageWidget(Widget):

    def__init__(self,**kwargs):
        super(MyImageWidget,self).__init__(**kwargs)
        self.image = Image(source='go.jpg')
        self.add_widget(self.image)
        Clock.schedule_interval(self.update_pic,1)

    defupdate_pic(self,dt):
        self.image.reload()


classMyApp(App):
    defbuild(self):
        return MyImageWidget()


MyApp().run()

Solution 3:

You can use the Image.reload method

defbuild(self):
    img = Image(source='go.jpg')
    Clock.schedule_interval(lambdadt: img.reload(), 0.2) #5 per secondreturn img

Post a Comment for "How Can I Reload A Image In Kivy Python"