Reputation: 178
Regarding a Kivy Image widget. I can't seem to figure out how to remove the source to make it blank.
For example :
kivy_image_widget.source = None
I would like to clear the contents of an image widget when there is no data to display.
Thanks, Dan
Upvotes: 1
Views: 2166
Reputation: 16041
Since source is a StringProperty, assign an empty string to it.
kivy_image_widget.source = ''
source
Filename / source of your image.
source is a StringProperty and defaults to None.
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
class RootWidget(BoxLayout):
def clear_image(self):
self.ids.img2.source = ''
self.ids.img2.reload()
class TestApp(App):
def build(self):
return RootWidget()
if __name__ == "__main__":
TestApp().run()
#:kivy 1.11.0
<RootWidget>:
orientation: 'vertical'
Image:
id: img1
source: 'kivyLogo.png'
Image:
id: img2
source: 'raspberrypi.png'
Button:
text: 'Clear Image 2'
size_hint_y: 0.1
on_release:
root.clear_image()
Upvotes: 2
Reputation: 309
If you just need to make it blank, use opacity
property like this:
kivy_image_widget.opacity = 0
Upvotes: 0