gpt4 book ai didi

python - 使用 KivyMD 时更改主调色板颜色对按钮没有影响

转载 作者:行者123 更新时间:2023-11-30 04:58:04 24 4
gpt4 key购买 nike

因此,我正在尝试使用 Kivy 构建一个应用程序,最近,我了解了 KivyMD 但被卡住了。当我更改主调色板颜色时,每个按钮都保持蓝色,但 MDDropDownMenu 会发生变化。我尝试在构建方法之前和构建方法中使用它,但它仍然只对 MDDropDownMenu 有效。什么会导致这种情况?

主要.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:

最佳答案

您可以使用以下方法更改按钮颜色:MDFillRoundFlatIconButton:md_bg_color: [0, 0, 0, .3]

我只是希望这会有所帮助!

关于python - 使用 KivyMD 时更改主调色板颜色对按钮没有影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58787864/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com