2

So I'm trying to build an app using Kivy and, recently, I learned about KivyMD but got stuck. When I change primary palette color it stays blue for every button, but changes for MDDropDownMenu. I tried using it both before and in build method, and still it worked only for MDDropDownMenu. What can cause this?

main.py:

from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.config import Config
from kivy.properties import ObjectProperty
from root.ModelPrep import validate_params, change_koatuu, prep_params, load_regression
from kivymd.theming import ThemeManager
from kivymd.toast import toast


class MainWindow(Screen):...
class LoadWindow(Screen):...
class ResultWindow(Screen):...


class WindowManager(ScreenManager):
    pass


# kv_non_md = Builder.load_file('deepeval_non_md.kv')
kv_md = Builder.load_file('deepeval_md.kv')


class DeepEval(App):

    theme_cls = ThemeManager()
    title = 'DeepEval'
    main_widget = None

    menu_items = []

    def callback_for_menu_items(self, *args):
        toast(args[0])

    def build(self):
        self.theme_cls.primary_palette = 'Teal'
        self.theme_cls.theme_style = 'Light'
        self.menu_items = [{
                "viewclass": "MDMenuItem",
                "text": "Example item %d" % i,
                "callback": self.callback_for_menu_items,
            }
            for i in range(15)
        ]
        return kv_md


if __name__ == '__main__':
    DeepEval().run()

deepeval_md.kv:

#:import Factory kivy.factory.Factory
#:import Clock kivy.clock.Clock
#:import MDDropdownMenu kivymd.uix.menu.MDDropdownMenu

WindowManager:
    MainWindow:
    LoadWindow:
    ResultWindow:

<MainWindow>
    name: 'main'

    koatuu_obl_cent: koatuu_obl_cent
    koatuu_city: koatuu_city
    kitchen_area: kitchen_area
    qt_room: qt_room
    floor: floor
    qt_floor: qt_floor
    total_area: total_area
    living_area: living_area
    year_building: year_building

    AnchorLayout:
        anchor_x: 'center'
        anchor_y: 'center'
        size: root.width, root.height

        BoxLayout:
            orientation: 'vertical'
            height: 350
            width: 225
            size_hint_x: None
            size_hint_y: None
            spacing: 22.5

            MDTextFieldRect:
                id: total_area
                multiline: False
                hint_text: "Param12"
                halign: 'center'
                height: 33
                width: 225
                size_hint_x: None
                size_hint_y: None

            MDTextFieldRect:
                id: kitchen_area
                multiline: False
                hint_text: "Param1"
                halign: 'center'
                height: 33
                width: 225
                size_hint_x: None
                size_hint_y: None

            MDTextFieldRect:
                id: living_area
                multiline: False
                hint_text: "Param1"
                halign: 'center'
                height: 33
                width: 225
                size_hint_x: None
                size_hint_y: None

            MDTextFieldRect:
                id: qt_room
                multiline: False
                hint_text: "Param1"
                halign: 'center'
                height: 33
                width: 225
                size_hint_x: None
                size_hint_y: None

            MDTextFieldRect:
                id: floor
                multiline: False
                hint_text: "Param1"
                halign: 'center'
                height: 33
                width: 225
                size_hint_x: None
                size_hint_y: None

            MDTextFieldRect:
                id: qt_floor
                multiline: False
                hint_text: "Param1"
                halign: 'center'
                height: 33
                width: 225
                size_hint_x: None
                size_hint_y: None

            MDTextFieldRect:
                id: year_building
                multiline: False
                hint_text: "Param1"
                halign: 'center'
                height: 33
                width: 225
                size_hint_x: None
                size_hint_y: None

            MDFillRoundFlatButton:
                id: koatuu_obl_cent
                text: 'Open popup'
                pos_hint: {'center_x': .5}
                on_release: MDDropdownMenu(items=app.menu_items, width_mult=3).open(self)
                height: 33
                width: 225
                size_hint_x: None
                size_hint_y: None

            MDFillRoundFlatButton:
                id: koatuu_city
                pos_hint: {'center_x': .5}
                text: 'Open popup'
                on_release: MDDropdownMenu(items=app.menu_items, width_mult=3).open(self)
                height: 33
                width: 225
                size_hint_x: None
                size_hint_y: None

        AnchorLayout:
            anchor_x: "center"
            anchor_y: "bottom"
            padding: 0,0,0,25

            MDFillRoundFlatButton:
                text: "Calculate"
                size_hint_x: None
                size_hint_y: None
                height: 50
                on_press: app.root.current = 'load'
                on_release:
ArtemSBulgakov
  • 973
  • 10
  • 21
Kojimba
  • 83
  • 1
  • 8

3 Answers3

2

you can just change the button color using this: MDFillRoundFlatIconButton: md_bg_color: [0, 0, 0, .3]

I just hope this will help!

Gabriel J
  • 66
  • 7
1

You will also need to add an import line of 'from kivymd.app import MDApp'. See https://kivymd.readthedocs.io/en/latest/getting-started/

0

While KivyMD is in alpha status, it may contain bugs. Widgets in KivyMD 0.102.0 set their colors on initialization. In your case the best way to fix it will be loading .kv file inside build function:

    def build(self):
        self.theme_cls.primary_palette = "Teal"
        self.theme_cls.theme_style = "Light"
        # ...
        kv_md = Builder.load_file("deepeval_md.kv")
        return kv_md
ArtemSBulgakov
  • 973
  • 10
  • 21