使用 MDRectangleFlatButton 和 MDRaisedButton 时的时钟警告
Clock warning when using MDRectangleFlatButton and MDRaisedButton
我正在使用 kivy 和 kivymd 制作桌面应用程序,在为应用程序创建设置屏幕时,我使用了两个 MDRectangleFlatButon 和 MDRaisedButtons但是为了使它们具有可扩展性,我给了它们两个 size_hint_x 的 .5,每个都占据了屏幕的一半。但是,程序一启动,我就收到来自 kivy 的警告:
[CRITICAL] [Clock ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
有趣的是,如果我将当前屏幕切换到我在其中定义的屏幕,警告就会停止。为什么我会收到此警告,我该如何阻止它?我的 python 文件:
from kivy.config import Config
Config.set('graphics', 'width', '850')
Config.set('graphics', 'height', '530')
Config.set('graphics', 'minimum_width', '850')
Config.set('graphics', 'minimum_height', '530')
from kivy.lang import Builder
from kivymd.uix.card import MDCard
from kivymd.uix.tab import MDTabsBase
from kivymd.app import MDApp
class SettingsTab(MDCard, MDTabsBase):
pass
class Example(MDApp):
def __init__(self, **kwargs):
super(Example, self).__init__(**kwargs)
self.kv = Builder.load_file("design.kv")
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Blue"
self.theme_cls.accent_palette = "Teal"
return self.kv
if __name__ == '__main__':
Example().run()
我的 kv 文件:
#:kivy 2.0.0
<SettingsTab>:
orientation: "vertical"
size_hint: .95, .95
pos_hint: {"center_x": .5, "center_y": .5}
border_radius: 5
radius: [5]
elevation: 20
BoxLayout:
MDNavigationRail:
color_active: app.theme_cls.primary_color
MDNavigationRailItem:
icon: "list-status"
on_release:
screens.current = "downloads_screen"
MDNavigationRailItem:
icon: "cog"
on_release:
screens.current = "settings"
MDNavigationRailItem:
icon: "information"
on_release:
screens.current = "activity_log"
ScreenManager:
id: screens
Screen:
name: "downloads_screen"
Screen:
name: "activity_log"
Screen:
name: "settings"
MDTabs:
SettingsTab:
title: "DOWNLOAD"
SettingsTab:
title: "COLOR"
MDBoxLayout:
adaptive_height: True
orientation: "vertical"
padding: 10
MDLabel:
text: "Theme Manager: "
font_style: "H5"
padding_y: 10
size_hint_y: None
height: self.texture_size[1]
MDBoxLayout:
adaptive_height: True
spacing: 10
MDRectangleFlatButton:
text: "See Current Palette"
size_hint_x: .5
MDRaisedButton:
text: "Open Theme Picker"
size_hint_x: .5
SettingsTab:
title: "INFO"
编辑: 顺便提一下,我不只是想让警告消失,我还想阻止性能下降。即使我没有将 size_hint 添加到任何按钮(不再导致错误),应用程序也会变得非常缓慢和缓慢。调整程序大小时会有很大的延迟,当程序启动时它确实在我的 cpu 上做一个数字并且在我切换到那个框架之前它不会改变。
如果您更改 Screens
定义的顺序,使“设置”Screen
在您的 kv
中第一个列在 ScreenManager
下,则错误信息消失。然后添加到 Example
class 定义:
def on_start(self):
self.kv.ids.screens.transition = NoTransition()
self.kv.ids.screens.current = 'downloads_screen'
self.kv.ids.screens.transition = SlideTransition()
使 downloads_screen
先出现。
我正在使用 kivy 和 kivymd 制作桌面应用程序,在为应用程序创建设置屏幕时,我使用了两个 MDRectangleFlatButon 和 MDRaisedButtons但是为了使它们具有可扩展性,我给了它们两个 size_hint_x 的 .5,每个都占据了屏幕的一半。但是,程序一启动,我就收到来自 kivy 的警告:
[CRITICAL] [Clock ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute
有趣的是,如果我将当前屏幕切换到我在其中定义的屏幕,警告就会停止。为什么我会收到此警告,我该如何阻止它?我的 python 文件:
from kivy.config import Config
Config.set('graphics', 'width', '850')
Config.set('graphics', 'height', '530')
Config.set('graphics', 'minimum_width', '850')
Config.set('graphics', 'minimum_height', '530')
from kivy.lang import Builder
from kivymd.uix.card import MDCard
from kivymd.uix.tab import MDTabsBase
from kivymd.app import MDApp
class SettingsTab(MDCard, MDTabsBase):
pass
class Example(MDApp):
def __init__(self, **kwargs):
super(Example, self).__init__(**kwargs)
self.kv = Builder.load_file("design.kv")
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Blue"
self.theme_cls.accent_palette = "Teal"
return self.kv
if __name__ == '__main__':
Example().run()
我的 kv 文件:
#:kivy 2.0.0
<SettingsTab>:
orientation: "vertical"
size_hint: .95, .95
pos_hint: {"center_x": .5, "center_y": .5}
border_radius: 5
radius: [5]
elevation: 20
BoxLayout:
MDNavigationRail:
color_active: app.theme_cls.primary_color
MDNavigationRailItem:
icon: "list-status"
on_release:
screens.current = "downloads_screen"
MDNavigationRailItem:
icon: "cog"
on_release:
screens.current = "settings"
MDNavigationRailItem:
icon: "information"
on_release:
screens.current = "activity_log"
ScreenManager:
id: screens
Screen:
name: "downloads_screen"
Screen:
name: "activity_log"
Screen:
name: "settings"
MDTabs:
SettingsTab:
title: "DOWNLOAD"
SettingsTab:
title: "COLOR"
MDBoxLayout:
adaptive_height: True
orientation: "vertical"
padding: 10
MDLabel:
text: "Theme Manager: "
font_style: "H5"
padding_y: 10
size_hint_y: None
height: self.texture_size[1]
MDBoxLayout:
adaptive_height: True
spacing: 10
MDRectangleFlatButton:
text: "See Current Palette"
size_hint_x: .5
MDRaisedButton:
text: "Open Theme Picker"
size_hint_x: .5
SettingsTab:
title: "INFO"
编辑: 顺便提一下,我不只是想让警告消失,我还想阻止性能下降。即使我没有将 size_hint 添加到任何按钮(不再导致错误),应用程序也会变得非常缓慢和缓慢。调整程序大小时会有很大的延迟,当程序启动时它确实在我的 cpu 上做一个数字并且在我切换到那个框架之前它不会改变。
如果您更改 Screens
定义的顺序,使“设置”Screen
在您的 kv
中第一个列在 ScreenManager
下,则错误信息消失。然后添加到 Example
class 定义:
def on_start(self):
self.kv.ids.screens.transition = NoTransition()
self.kv.ids.screens.current = 'downloads_screen'
self.kv.ids.screens.transition = SlideTransition()
使 downloads_screen
先出现。