Search code examples
python-3.xkivykivy-language

How to pass arguments between scripts and functions


I am making a kivy app and I have been looking for a way to pass variables from one script (script 1) to another (script 2). Once the variables are now in script 2, i want to pass them from one function to another, where the variables will then be added to a listview in my kivy app. The data being sent from Script 1.py was from Script 1.kv.

code snippet

Or is there an easier way to send input data from Script1.kv to Script2.py Thank you in advance


Solution

  • Since you using Screens you may use a global ScreenManager to get reference to them

    from script2 import Results
    
    class Sender(Screen):
        ...
        def send(self):
            r = sm.get_screen('results')
            r.get(start, end price)
    sm = None
    
    class YourApp(App):
        def build(self):
            global sm
            sm = ScreenManager()
            sm.add_widget(Results(name='results'))
            sm.add_widget(Sender(name='sender'))
            return sm