Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
470 views
in Technique[技术] by (71.8m points)

python - CRITICAL] [Clock ] Warning, too much iteration done before the next frame

I'm just learning, and I tried to run this simple code : ihave a problem , can we help me : this is my code for my apps:

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()

The console repeatedly gives this error, but the window pops up just fine:

[CRITICAL ] [Clock ] Warning, too much iteration done before the next frame. Check your code, or increase the Clock.max_iteration attribute

question from:https://stackoverflow.com/questions/65872131/critical-clock-warning-too-much-iteration-done-before-the-next-frame

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try removing the sm lines after the Create the screen manager comment:

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

Those lines are building a widget tree that is not used anywhere. The actual widget tree is built by:

screen = Builder.load_string(Screen_helper)

Not sure if that will fix your problem, but it should help.

If that doesn't work, you can do as the warning suggests:

from kivy.clock import Clock
Clock.max_iteration = 20

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...