Reputation:
I am facing problems in using kvlang with the python code because I am very new to kivy and kivymd, and I am learning kivy on my own.
I need your help and guidance in learning KIVY.
I want to access 'md_bg_color' from 'tut_1.kv' and change it's value from 'tut_1.py'.
tut_1.py
from kivymd.app import MDApp
from kivy.lang.builder import Builder
from random import randint
class tut_1(MDApp):
def build(self):
return Builder.load_file('/home/kali/Documents/Kivy/kivymd Tutorial/kv_lang/tut_1.kv')
tut_1().run()
tut_1.kv
MDScreen:
id: can
radius: [90, 90, 90, 90]
md_bg_color: (1,0,0,.3)
THANK YOU VERY MUCH FOR GIVING YOUR VALUABLE TIME TO HELP ME.
Upvotes: 0
Views: 126
Reputation: 39082
The md_bg_color
is just a property of the MDScreen
. The MDScreen
is the root of your MDApp
because is is the return
of your build()
method. So, from any method of your tut_1
class, you can modify md_bg_color
like this:
self.root.md_bg_color = (0,1,0,1)
If you are accessing it from outside the tut_1
class, you can use:
MDApp.get_running_app().root.md_bg_color = (0,1,0,1)
Upvotes: 0