【发布时间】:2019-11-10 10:45:36
【问题描述】:
所以我正在尝试使用 Kivy 构建一个应用程序,最近,我了解了 KivyMD,但被卡住了。当我更改主调色板颜色时,每个按钮都保持蓝色,但 MDDropDownMenu 会发生变化。我尝试在构建方法之前和构建方法中都使用它,但它仍然只适用于 MDDropDownMenu。这是什么原因造成的?
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:
【问题讨论】:
标签: python android kivy kivy-language