Image goes black when source is updated

12 views
Skip to first unread message

Nico De Ranter

unread,
Nov 20, 2021, 6:17:46 AM11/20/21
to kivy-...@googlegroups.com
I have a kivy app that displays a png file. Every once in a while I want to update the image.  I've set the source of the image to point at a variable 'weather_icon' in my main class and defined that to be a StringProperty.  I set the value in my build function which seems to work fine. Later on I update the value and the image goes black.  So it looks like it does get the update, but it is not rendering correctly.  I'm sure the filename is correct, exists and is usable as I do see the correct image when I use it initially in the build function.  I googled around but all I could find was to use the StringProperty, which I'm already doing.
What am I missing here? 

kivy version: v2.1.0.dev0 
kv file:
...
<WeatherWidgetMedium@FloatLayout>:
    size_hint: None, None
    size: 400, 260
    weathermedium: weathermedium
    Image:
        id: weathermedium
        size_hint: None, None
        size: 220,220
        pos_hint: { 'center_x': 0.4, 'center_y': 0.5 }
        allow_stretch: True
        source: app.weather_icon
...

python:
class TouchMainApp(App):
    weather_icon = StringProperty('')

   def build(self):
        self.weather_icon='../static/icons/wi-day-sunny.png'
        kv = Builder.load_file('../static/touch.kv')

    def pidoraWeatherCallback(self, dummy, topic, infotype, payload):
        icon='../static/icons/somenewweathericon.png'
        self.weather_icon=icon
--
Nico & Ann De Ranter - Van Aelst

Elliot Garbus

unread,
Nov 20, 2021, 9:48:12 AM11/20/21
to kivy-...@googlegroups.com

The code looks fine.

Make sure the path to the new file is correct.

Check if there are any errors in the log.  If you have a kv file named touchmain.kv, there may be 2 kv files loading.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAJoVLP61RODrzYAUghX4_z%2BgU0AENjh6ZHgOOyJ-Pc8NKz4T4w%40mail.gmail.com.

 

Nico De Ranter

unread,
Nov 20, 2021, 1:53:10 PM11/20/21
to kivy-...@googlegroups.com
I'm quite sure the path is correct. I added a print(icon) and used the output for the initial value and then I do see the icon.
I only have one kv file in my source tree so that shouldn't be a problem either.  Unfortunately the logs are not showing anything when I change the icon.

Thanks for confirming the code looks ok, at least that confirms I understood the procedure correctly. I'll just keep banging my head against the wall until it starts working :-)

Thanks for your fast reply.

Nico

Op za 20 nov. 2021 om 15:48 schreef Elliot Garbus <elli...@cox.net>:
Reply all
Reply to author
Forward
0 new messages