因此,我试图使用 Kivy 来构建应用程序,最近,我了解了 KivyMD ,但遇到了麻烦。当我更改主调色板颜色时,每个按钮均保持蓝色,而对于 MDDropDownMenu 则更改。我尝试在构建方法之前和构建方法中都使用它,但它仍然仅对 MDDropDownMenu 有效。是什么原因造成的?
main.py:
SELECT A.P1, A.P2, B.P3, B.ID
FROM A
LEFT JOIN B
ON A.ID = B.A_ID
deepeval_md.kv:
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()
答案 0 :(得分:1)
您还需要添加“from kivymd.app import MDApp”的导入行。见https://kivymd.readthedocs.io/en/latest/getting-started/
答案 1 :(得分:0)
您可以使用以下命令更改按钮颜色: MDFillRoundFlatIconButton: md_bg_color:[0、0、0,.3]
我只是希望这会有所帮助!
答案 2 :(得分:0)
KivyMD 处于 alpha 状态时,可能包含错误。 KivyMD 0.102.0 中的小部件在初始化时设置其颜色。根据您的情况,修复此问题的最佳方法是在 build 函数中加载.kv文件:
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