I know that we can access variables declared in the main class of the app. This can be done using "app.NameOfTheVariable", for example, access to a string value:
#Python file
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
class MainScreen(MDBoxLayout):
pass
class MainApp(MDApp):
App_Name = "Galasken Proyect 001"
MainApp.run()
#Kivy file
MainScreen:
<MainScreen>:
MDLabel:
text: app.App_name
However, I want to know how can we access variables that are inside a function which is inside a class. For example, in the next code, how can I access to "Object_name"
#Python file
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
class MainScreen(MDBoxLayout):
pass
class MainApp(MDApp):
App_Name = "App Example"
def a_function(self):
Object_name = "this is a name"
MainApp.run()
I have tried different things on the kivy file but nothing have workd. These are the things that I have tried:
#Kivy file
MainScreen:
<MainScreen>:
MDLabel:
text: app.a_function().App_name
# text: app.a_function.App_name
# text: app.App_name
What can I do to access that variable?