Skip to content

Instantly share code, notes, and snippets.

@wishrohitv
Created April 22, 2024 11:07
Show Gist options
  • Save wishrohitv/ec8651174dbf9a9c0fabf01c0193e935 to your computer and use it in GitHub Desktop.
Save wishrohitv/ec8651174dbf9a9c0fabf01c0193e935 to your computer and use it in GitHub Desktop.
# firstbox.py
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty
kv = """
<FirstBox>:
Button:
text: 'First box: send message to second box'
on_release: root.dispatch('on_release')
Label:
text: root.text
"""
Builder.load_string(kv)
class FirstBox(BoxLayout):
__events__ = ['on_release']
text = StringProperty('First Box initial value')
def on_release(self):
pass
# secondbox.py
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty
kv = """
<SecondBox>:
Button:
text: 'Second box: send message to second box'
on_release: root.dispatch('on_release')
Label:
text: root.text
"""
Builder.load_string(kv)
class SecondBox(BoxLayout):
__events__ = ['on_release']
text = StringProperty('second Box initial value')
def on_release(self):
pass
# main.py
from kivy.app import App
from kivy.lang import Builder
import firstbox
import secondbox
kv = """
BoxLayout: # root widget
orientation: 'vertical'
FirstBox:
id: fb
on_release: sb.text = 'sent from first box!'
SecondBox:
id: sb
on_release: fb.text = 'sent from second box'
"""
class ClasstoClassApp(App):
def build(self):
return Builder.load_string(kv)
ClasstoClassApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment