I´m trying to achieve the following: capture the text from from Label: id: fb in screen FolderB and copy/add to Label: id: fa in screen FolderA by pressing the Button "get the txt from Folder B". Please find the codes below: Thanks in advance,
file main.py
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
Builder.load_file('foldera.kv')
Builder.load_file('folderb.kv')
class MainScreen(ScreenManager):
pass
class FolderA(Screen):
pass
class FolderB(Screen):
pass
class FTest(App):
def build(self):
return MainScreen()
if __name__ == '__main__':
FTest().run()
file ftest.kv (class build)
<FolderA@FolderA>
<FolderB@FolderB>
<MainScreen>:
FolderA:
name: 'foldera'
FolderB:
name: 'folderb'
file foldera.kv (boxlayout)
<FolderA>:
BoxLayout:
orientation: 'vertical'
Label:
text: 'Folder A'
Button:
text: 'go to Folder B'
on_press: app.root.current = 'folderb'
Label:
id: fa
text: ''
Button:
text: 'get text from Folder B'
on_press: "this is the button where i'm trying to apply the action"
file folderb.kv (boxlayout)
<FolderB>:
BoxLayout:
orientation: 'vertical'
Label:
text: 'Folder B'
Button:
text: 'go to Folder B'
on_press: app.root.current = 'foldera'
Label:
id: fb
text: 'TEXT: CAPTURE THIS TEXT'
You could save the shared variable in the
App
class, for example.Then you can access it in kv, by writing
app.label_a
Try this example: