Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ivlevdenis/ff4f39d9f82b6dd66a77 to your computer and use it in GitHub Desktop.
Save ivlevdenis/ff4f39d9f82b6dd66a77 to your computer and use it in GitHub Desktop.
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.lang import Builder
from kivy.properties import StringProperty
kv = '''
<MyWidget>:
canvas:
Rectangle:
size: self.size
pos: self.pos
source: self.background
BoxLayout:
MyWidget:
MyWidget:
MyWidget:
'''
class MyWidget(Widget):
background = StringProperty('')
instances = []
def __init__(self, **kwargs):
super(MyWidget, self).__init__(**kwargs)
MyWidget.instances.append(self)
@staticmethod
def set_all_backgrounds(background):
for widget in MyWidget.instances:
widget.background = background
class TestApp(App):
def build(self):
root = Builder.load_string(kv)
MyWidget.set_all_backgrounds('cover.jpg')
return root
TestApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment