Kv language has a way to import names from other files using the following syntax:
#:import name x.y.z
# The same as `from x.y import z as name` in Python code
But it doesn't mention how to import the values from the same module where that kv language is used.
Let's say I have the following code:
from kivy.app import App
from kivy.lang import Builder
from kivy.atlas import Atlas
from kivy.uix.button import Button
theme = Atlas('path/to/atlas')
Builder.load_string('''
<MyWidget>:
background_normal: theme['widget_bg']
''')
class MyWidget(Button):
pass
class TestApp(App):
def build(self):
return MyWidget()
TestApp().run()
I'd like to import the theme
Atlas object into the kv code to set the proper background. How could this be done?
You can refer to your current module as __main__