KivyMD - MDRectangleFlatButton - слишком медленная анимация тени кнопки
Пожалуйста, помогите мне выяснить, как ускорить анимацию тени кнопки для KivyMD MDRectangleFlatButton. Согласно документации нет прямого параметра, который я могу изменить.
файл python:
from kivy.app import App
from kivymd.theming import ThemeManager
from kivymd.app import MDApp
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import ScreenManager, Screen
class ContentNavigationDrawer(BoxLayout):
pass
class Screen2(Screen):
pass
sm = ScreenManager()
sm.add_widget(Screen2(name='s2'))
class MainApp(MDApp):
def build(self):
pass
MainApp().run()
kv файл:
Screen:
NavigationLayout:
ScreenManager:
id: screen_manager
Screen:
name: 'menu'
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Navigation Drawer"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.set_state("toggle")]]
Widget:
Screen2:
name: 's2'
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Screen2"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.set_state("toggle")]]
Widget:
MDLabel:
text: 'Profile'
halign: 'center'
MDNavigationDrawer:
id: nav_drawer
ContentNavigationDrawer:
BoxLayout:
orientation: 'vertical'
MDLabel:
text: 'App'
font_style: 'H1'
MDRectangleFlatButton:
text: 'Select 1'
pos_hint: {'center_x':0.5,'center_y':0.1}
on_release:
screen_manager.current = 's2'
nav_drawer.set_state("toggle")
MDRectangleFlatButton:
text: 'Main'
pos_hint: {'center_x':0.5,'center_y':0.1}
on_release:
screen_manager.current = 'menu'
nav_drawer.set_state("toggle")
У меня задержка анимации: Анимация кнопок
Итак, как действия:
- откройте ящик;
- выберите один из вариантов в нижнем меню
- ящик закрывается, но на экране остается анимация кнопок.
Спасибо!
1 ответ
Решение
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.screen import MDScreen
KV = """
#:import Clock kivy.clock.Clock
MDScreen:
NavigationLayout:
ScreenManager:
id: screen_manager
MDScreen:
name: 'menu'
MDToolbar:
title: "Navigation Drawer"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.set_state("toggle")]]
pos_hint: {"top": 1}
Screen2:
name: 's2'
MDToolbar:
title: "Screen2"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.set_state("toggle")]]
pos_hint: {"top": 1}
MDLabel:
text: 'Profile'
halign: 'center'
MDNavigationDrawer:
id: nav_drawer
ContentNavigationDrawer:
orientation: 'vertical'
adaptive_height: True
pos_hint: {"top": 1}
spacing: "12dp"
MDLabel:
text: 'App'
font_style: 'H1'
size_hint_y: None
height: self.texture_size[1]
MDRectangleFlatButton:
text: 'Select 1'
pos_hint: {'center_x':0.5,'center_y':0.1}
on_release: Clock.schedule_once(lambda x: app.set_screen(screen_manager, nav_drawer, "s2"), .3)
MDRectangleFlatButton:
text: 'Main'
pos_hint: {'center_x':0.5,'center_y':0.1}
on_release: Clock.schedule_once(lambda x: app.set_screen(screen_manager, nav_drawer, "menu"), .3)
"""
class ContentNavigationDrawer(MDBoxLayout):
pass
class Screen2(MDScreen):
pass
sm = ScreenManager()
sm.add_widget(Screen2(name='s2'))
class MainApp(MDApp):
def build(self):
return Builder.load_string(KV)
def set_screen(self, manager, nav_drawer, name_screen):
manager.current = name_screen
nav_drawer.set_state("toggle")
MainApp().run()