【问题标题】:CRITICAL] [Clock ] Warning, too much iteration done before the next frameCRITICAL] [Clock ] 警告,在下一帧之前完成了太多迭代
【发布时间】:2021-01-24 15:00:57
【问题描述】:

我只是在学习,我尝试运行这个简单的代码: 我有问题,我们能帮帮我吗: 这是我的应用程序代码:

from kivymd.app import MDApp
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import ScreenManager, Screen


Screen_helper = """
ScreenManager:
    MenuScreen:
    InscriptionScreen:
    LoginScreen:
<MenuScreen>:
    name: 'menu'
    MDRectangleFlatButton:
        text: 'Inscription'
        pos_hint: {'center_x':0.5,'center_y':0.6}
        on_press: root.manager.current = 'Inscription'
    MDRectangleFlatButton:
        text: 'Login'
        pos_hint: {'center_x':0.5,'center_y':0.5}
        on_press: root.manager.current = 'Login'

<InscriptionScreen>:
    name: 'Inscription'
    MDLabel:
        text: "Inscription"
        pos_hint: {"center_y": .85}
        font_style:"H4"
        halign : "center"
        theme_text_color : "Custom"
        text_color : 0, 0, 0, 1
    MDTextField:
        hint_text: "Enter First Name"
        icon_right:"account"
        pos_hint:{'center_x':0.5,'center_y':0.7}
        size_hint_x:None
        width:300
    MDTextField:
        hint_text: "Enter Last Name"
        icon_right : "account"
        pos_hint:{'center_x':0.5,'center_y':0.6}
        size_hint_x:None
        width:300
    MDTextField:

        hint_text: "Enter Email"
        icon_right: "mail"
        pos_hint: {'center_x': 0.5, 'center_y': 0.5}
        size_hint_x: None
        width: 300
    MDTextField:
        hint_text: "Enter Username"
        icon_right:"account-plus"
        pos_hint:{'center_x':0.5,'center_y':0.4}
        size_hint_x:None
        width:300
    MDTextField:
        hint_text: "Enter Password"
        icon_right:"lock"
        pos_hint:{'center_x':0.5,'center_y':0.3}
        size_hint_x:None
        width:300
        password: True
    MDTextField:
        hint_text: "Confirm Password"
        icon_right:"lock"
        pos_hint:{'center_x':0.5,'center_y':0.2}
        size_hint_x:None
        width:300
        password: True
    MDRaisedButton:
        text:"Valider"
        font_style:"H4"
        type: 'bottom'
        pos_hint: {'center_x':0.5,'center_y':0.08}
        size_hint_x: 0.5
    MDRectangleFlatButton:
        text: ' re'
        icon:"keyboard-return"
        pos_hint: {'center_x':0.1,'center_y':0.9}
        on_press: root.manager.current = 'menu'
        type : 'Detour'
<LoginScreen>:
    name: 'Login'
    MDLabel:
        text: "Login"
        pos_hint: {"center_y": .85}
        font_style:"H4"
        halign : "center"
        theme_text_color : "Custom"

        
    MDTextField:
        hint_text: "Username"
        icon_right:"account"
        pos_hint:{'center_x':0.5,'center_y':0.7}
        size_hint_x:None
        width:300

    MDTextField:
        hint_text: "Password"
        icon_right : "lock"
        pos_hint:{'center_x':0.5,'center_y':0.6}
        size_hint_x:None
        width:300
        password : True

    MDRaisedButton:
        text:"Log in"
        pos_hint: {'center_x':0.5,'center_y':0.4}
        size_hint_x: 0.5
    MDRectangleFlatButton:
        text: 'Back'
        pos_hint: {'center_x':0.9,'center_y':0.1}
        on_press: root.manager.current = 'menu'
      
"""


class MenuScreen(Screen):
    pass


class InscriptionScreen(Screen):
    pass


class LoginScreen(Screen):
    pass





# Create the screen manager
sm = ScreenManager()
sm.add_widget(MenuScreen(name="menu"))
sm.add_widget(InscriptionScreen(name="Inscription"))
sm.add_widget(LoginScreen(name="Login"))


class DemoApp(MDApp):

    def build(self):
        screen = Builder.load_string(Screen_helper)
        return screen


DemoApp().run()

控制台反复报此错误,但弹出窗口就好了:

[CRITICAL ] [Clock ] 警告,在下一帧之前完成了太多迭代。检查你的代码,或者增加 Clock.max_iteration 属性

【问题讨论】:

    标签: python kivy kivymd


    【解决方案1】:

    尝试删除Create the screen manager 注释后的sm 行:

    # Create the screen manager
    sm = ScreenManager()
    sm.add_widget(MenuScreen(name="menu"))
    sm.add_widget(InscriptionScreen(name="Inscription"))
    sm.add_widget(LoginScreen(name="Login"))
    

    这些行正在构建一个未在任何地方使用的小部件树。实际的小部件树由以下人员构建:

    screen = Builder.load_string(Screen_helper)
    

    不确定这是否能解决您的问题,但应该会有所帮助。

    如果这不起作用,您可以按照警告提示进行操作:

    from kivy.clock import Clock
    Clock.max_iteration = 20
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-21
      • 1970-01-01
      • 2019-04-12
      • 1970-01-01
      • 1970-01-01
      • 2016-11-08
      • 2012-10-13
      • 2016-11-04
      相关资源
      最近更新 更多