【问题标题】:Clock warning when using MDRectangleFlatButton and MDRaisedButton使用 MDRectangleFlatButton 和 MDRaisedButton 时的时钟警告
【发布时间】:2021-06-10 15:57:18
【问题描述】:

我正在使用 kivy 和 kivymd 制作桌面应用程序,在为应用程序创建设置屏幕时,我使用了两个 MDRectangleFlatButon 和 MDRaisedButtons 但为了使它们具有可扩展性,我给了它们都是 size_hint_x of .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 上做一个数字,并且在我切换到该帧之前它不会改变。

【问题讨论】:

  • 不知道为什么会发生这种情况,但是如果您将“设置”Screen 作为ScreenManager 下的第一个列出在您的kv 中,那么它就会消失。
  • @JohnAnderson 问题是我不希望设置屏幕成为第一个显示的屏幕
  • @JohnAnderson 我更新了问题以使我的意图更清晰

标签: python python-3.x kivy kivy-language kivymd


【解决方案1】:

如果您更改Screens 定义的顺序,使“设置”Screen 成为kvScreenManager 下列出的第一个,则错误消息将消失。然后添加到Example 类定义中:

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首先出现。

【讨论】:

  • 到目前为止,这似乎就足够了。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-10
  • 2019-05-06
  • 1970-01-01
  • 2023-03-12
相关资源
最近更新 更多