Created
July 1, 2015 21:47
-
-
Save ivlevdenis/ff4f39d9f82b6dd66a77 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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