pythonpropertieskivyscreendata-transfer

Python Kivy: How can I transfer a particular Object from Screen A to Screen B?


I am very much new to Python Kivy in making application.

Now I am currently making an application that can access DB and manipulate data thru app.

In order for me to freely do this, I guess I have to freely transfer/pass data(object-other than string) from one screen to another. Desired Data: VO class will be assigned to transfer the multiple types of data

I am currently able to transfer single strings thru the code below:

self.manager.get_screen('screen_1').ids.label_id.text = desired_text

but by means of using this method seems to have limitation.

I freely want to transfer/pass non-string type of data from one to another screen as if I am sharing data similar to the one I ve shown below as an example:

class Test:
    def __init__(self.):
        vo = testVO()
        name = vo.name
        print(name)

class testVO()
    __name = ''
    @property
    def name(self):
       return self.__name

    def __init__(self):
       self.__name = 'mike'

if __name__ == '__main__':
   Test()

console: mike

Your kindness and Support would truly be appreciated.


Solution

  • If you define an ObjectProperty in your Screen, then you can pass any object to it:

    class MyScreen(Screen):
        some_obj = ObjectProperty(None)
    

    If the name of this Screen is screen_1, then you can pass an object as:

    self.manager.get_screen('screen_1').some_obj = any_object