I am currently trying to implement a toggle button in my KivyMD app, yet cannot make it work.
I tried running the example shown in the documentation, however I constantly receive the error AttributeError: 'ThemeManager' object has no attribute 'primary_dark'
.
Even after replacing the MDRectangleFlatButton
class with the normal MDButton
class or removing the line self.background_down = self.theme_cls.primary_light
this error still prevails.
The bug has been posted on the official GitHub (here and there) yet both issues were closed without a solution or an answer.
Has anyone found a working solution for toggle buttons?
Answers are highly appreciated.
The documentation’s example:
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.behaviors.toggle_behavior import MDToggleButton
from kivymd.uix.button import MDFlatButton
KV = '''
MDScreen:
MDBoxLayout:
adaptive_size: True
spacing: "12dp"
pos_hint: {"center_x": .5, "center_y": .5}
MyToggleButton:
text: "Show ads"
group: "x"
MyToggleButton:
text: "Do not show ads"
group: "x"
MyToggleButton:
text: "Does not matter"
group: "x"
'''
class MyToggleButton(MDFlatButton, MDToggleButton):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.background_down = self.theme_cls.primary_color
class Test(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
return Builder.load_string(KV)
Test().run()