Python kivymd-[Critical]警告,在下一帧之前完成了太多迭代。检查代码,或增加Clock.max\u迭代次数

Python kivymd-[Critical]警告,在下一帧之前完成了太多迭代。检查代码,或增加Clock.max\u迭代次数,python,performance,kivy,Python,Performance,Kivy,这是我的main.py: #!/usr/bin/env python3 from kivy.app import App from kivy.lang import Builder from kivy.metrics import dp from kivy.properties import ObjectProperty from kivy.uix.image import Image from kivy.uix.widget import Widget from kivy.uix.boxlay

这是我的main.py:

#!/usr/bin/env python3
from kivy.app import App
from kivy.lang import Builder
from kivy.metrics import dp
from kivy.properties import ObjectProperty
from kivy.uix.image import Image
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivymd.bottomsheet import MDListBottomSheet, MDGridBottomSheet
from kivymd.button import MDIconButton
from kivymd.date_picker import MDDatePicker
from kivymd.dialog import MDDialog
from kivymd.label import MDLabel
from kivymd.list import ILeftBody, ILeftBodyTouch, IRightBodyTouch, BaseListItem
from kivymd.material_resources import DEVICE_TYPE
from kivymd.navigationdrawer import MDNavigationDrawer, NavigationDrawerHeaderBase
from kivymd.selectioncontrols import MDCheckbox
from kivymd.snackbar import Snackbar
from kivymd.theming import ThemeManager
from kivymd.time_picker import MDTimePicker

Builder.load_file('main.kv')

class BoxTopLevel(BoxLayout):
    def on_release_next_button(self):
        # self.ids['sm'].current="mainscreen"
        if not self.ids['username'].text:
            Snackbar(text="Please enter a username first").show()
            return 1
        elif ' ' in self.ids['username'].text:
            Snackbar(text="Invalid username").show()
            return 1
        elif '\\' in self.ids['username'].text:
            Snackbar(text="Invalid username").show()
            return 1
        # elif '\\' in self.ids['username'].text:
        #   Snackbar(text="No slashes please").show()
        if self.check_if_user_exists():
            Snackbar(text="Welcome %s!" % (self.ids['username'].text)).show()
            self.ids['sm'].current='mainscreen'
            return 0

    def check_if_user_exists(self):
        return True

    def set_previous_date(self, date_obj):
        self.previous_date = date_obj
        # self.root.ids.date_picker_label.text = str(date_obj)

    def show_date_picker(self):
        self.date_dialog = MDDatePicker(self.set_previous_date)
        self.date_dialog.open()

    def show_time_picker(self):
        self.time_dialog = MDTimePicker()
        self.time_dialog.open()

    def show_send_error_dialog(self):
        content = MDLabel(font_style='Body1', theme_text_color='Secondary', text="This is a dialog with a title and some text. That's pretty awesome right!", size_hint_y=None, valign='top')
        content.bind(texture_size=content.setter('size'))
        self.dialog = MDDialog(title="This is a test dialog",
                               content=content,
                               size_hint=(.8, None),
                               height=dp(200),
                               auto_dismiss=False)

        self.dialog.add_action_button("Dismiss",
                                      action=lambda *x: self.dialog.dismiss())
        self.dialog.open()

    def stop_record(self):
        print("[INFO] Recording Stopped")
        Snackbar(text="Recording stopped").show()
        self.stop_record_button = self.ids['stop_record_button']
        self.stop_record_button.disabled = True
        self.ids['record_button'].disabled = False
        rec_file_path = ''

    def record(self):
        print("[INFO] Recording")
        Snackbar(text="Recording started").show()
        self.record_button = self.ids['record_button']
        self.record_button.disabled = True
        self.ids['stop_record_button'].disabled = False

    def export(self, username, date, time, *args, **kwargs):
        username, date, time = str(username), str(date), str(time)
        file_path = '/home/cocoa/KES/'
        file_name = username+'_'+date+'_'+time+'.csv'
        csv_string = username+','+date+','+time
        for arg in args:
            if type(arg) == str:
                csv_string += ','+arg
        f = open(file_path+file_name, 'w')
        f.write(csv_string+'\n')
        f.close
        return True, file_path+file_name

    def upload(self, csv_file_path, recording_file_path):
        print(csv_file_path, recording_file_path)

    def submit(self):
        try:
            date = str(self.date_dialog.day)+'-'+str(self.date_dialog.month)+'-'+str(self.date_dialog.year)
            print(date)
            if self.export(self.ids['username'].text, date, self.time_dialog.time, 'answer1', 'answer2')[0]:
                Snackbar(text="Woo hoo! It worked!").show()
            else:
                self.show_send_error_dialog()
        except:
            Snackbar(text="Please enter the date and time and try again").show()

class SamplerApp(App):
    theme_cls = ThemeManager()
    def build(self, *args, **kwargs):
        return BoxTopLevel()


SamplerApp().run()
这是我的主要观点

#:import Toolbar kivymd.toolbar.Toolbar
#:import ThemeManager kivymd.theming.ThemeManager
#:import MDNavigationDrawer kivymd.navigationdrawer.MDNavigationDrawer
#:import NavigationLayout kivymd.navigationdrawer.NavigationLayout
#:import NavigationDrawerDivider kivymd.navigationdrawer.NavigationDrawerDivider
#:import NavigationDrawerToolbar kivymd.navigationdrawer.NavigationDrawerToolbar
#:import NavigationDrawerSubheader kivymd.navigationdrawer.NavigationDrawerSubheader
#:import MDCheckbox kivymd.selectioncontrols.MDCheckbox
#:import MDSwitch kivymd.selectioncontrols.MDSwitch
#:import MDList kivymd.list.MDList
#:import OneLineListItem kivymd.list.OneLineListItem
#:import TwoLineListItem kivymd.list.TwoLineListItem
#:import ThreeLineListItem kivymd.list.ThreeLineListItem
#:import OneLineAvatarListItem kivymd.list.OneLineAvatarListItem
#:import OneLineIconListItem kivymd.list.OneLineIconListItem
#:import OneLineAvatarIconListItem kivymd.list.OneLineAvatarIconListItem
#:import MDTextField kivymd.textfields.MDTextField
#:import MDSpinner kivymd.spinner.MDSpinner
#:import MDCard kivymd.card.MDCard
#:import MDSeparator kivymd.card.MDSeparator
#:import MDDropdownMenu kivymd.menu.MDDropdownMenu
#:import get_color_from_hex kivy.utils.get_color_from_hex
#:import colors kivymd.color_definitions.colors
#:import SmartTile kivymd.grid.SmartTile
#:import MDSlider kivymd.slider.MDSlider
#:import MDTabbedPanel kivymd.tabs.MDTabbedPanel
#:import MDTab kivymd.tabs.MDTab
#:import MDProgressBar kivymd.progressbar.MDProgressBar
#:import MDAccordion kivymd.accordion.MDAccordion
#:import MDAccordionItem kivymd.accordion.MDAccordionItem
#:import MDAccordionSubItem kivymd.accordion.MDAccordionSubItem
#:import MDThemePicker kivymd.theme_picker.MDThemePicker
#:import MDBottomNavigation kivymd.tabs.MDBottomNavigation
#:import MDBottomNavigationItem kivymd.tabs.MDBottomNavigationItem
<BoxTopLevel>:
    orientation: 'vertical'
    Toolbar:
        id: toolbar
        title: 'Sampler'
        md_bg_color: app.theme_cls.primary_color
        background_palette: 'Primary'
        background_hue: '500'
        #left_action_items: [['menu', lambda x: app.root.toggle_nav_drawer()]]
        #right_action_items: [['dots-vertical', lambda x: app.root.toggle_nav_drawer()]]
    ScreenManager:
        id: sm
        Screen:
            name: "loginscreen"
            BoxLayout:
                spacing: 20
                padding: 20
                orientation: 'vertical'
                Widget:
                BoxLayout:
                    orientation: 'vertical'
                    padding: 10
                    spacing: 10
                    MDTextField:
                        id: username
                        hint_text: "Please enter your unique username"
                    MDCard:
                        size_hint_x: 1
                        BoxLayout:
                            padding: 10
                            spacing: 10
                            orientation: 'vertical'
                            MDLabel:
                                text: 'Please don\'t share this username'
                                theme_text_color: 'Secondary'
                                font_style: "Title"
                                size_hint_y: None
                                height: dp(36)
                            MDSeparator:
                                height: dp(1)
                            MDLabel:
                                text: "This application was developed in a hurry, So I didn't have the time to implement a proper login system. This system is temporary And I will impliment proper logins at later stages of development"
                                theme_text_color: "Primary"
                    MDRaisedButton:
                        size_hint_x: 1
                        text: "Next ->"
                        on_release: root.on_release_next_button()
        Screen:
            name: "mainscreen"
            MDBottomNavigation:
                id: bottom_navigation_demo
                MDBottomNavigationItem:
                    name: 'record_page'
                    text: "Record"
                    icon: "microphone"
                    BoxLayout:
                        orientation: 'vertical'
                        padding: 10
                        spacing: 10
                        MDCard:
                            size_hint: 1, 0.2
                            BoxLayout:
                                padding: 10
                                spacing: 10
                                orientation: 'vertical'
                                MDLabel:
                                    text: 'Hello!'
                                    theme_text_color: 'Secondary'
                                    font_style: "Title"
                                    size_hint_y: None
                                    height: dp(36)
                                MDSeparator:
                                    height: dp(1)
                                MDLabel:
                                    text: "Since the buzzer went off, now is the time when you freely record your thought through this app. I want you to be as free as possible, without having to worry about whether or not anyone else will find any meaning in what you're saying. You can go on for as long as you like, but please try and go on for three minutes. You don't have to be talking throughout, it's okay to fill the time with silence if you can't freely associate in that moment. There isn't any right or wrong here, it's not possible for there to be any right or wrong here. Do log in your stats before you start here:"
                                    theme_text_color: "Primary"
                        Widget:
                            size_hint_y: 0.02
                            BoxLayout:
                                padding: 10
                                spacing: 10
                                MDRaisedButton:
                                    id: record_button
                                    text: "Start Recording"
                                    on_press: root.record()
                                MDRaisedButton:
                                    id: stop_record_button
                                    text: "Stop Recording"
                                    on_press: root.stop_record()
                                    disabled: True
                MDBottomNavigationItem:
                    name: 'questions'
                    text: "Questions"
                    icon: "help"
                    GridLayout:
                        rows: 7
                        cols: 1
                        padding: dp(48)
                        spacing: 10
                        MDTextField:
                            id: location
                            multiline: True
                            hint_text: "Where are you?"
                        MDTextField:
                            id: task
                            multiline: True
                            hint_text: "What were you doing?"
                        MDTextField:
                            id: person_with
                            multiline: True
                            hint_text: "Who are you with"
                        MDTextField:
                            id: special_circumstances
                            multiline: True
                            hint_text: "Are there any special circumstances? (Inebriated, very sad, something big happened)"
                        MDRaisedButton:
                            id: date
                            size_hint: None, None
                            size: 3 * dp(48), dp(48)
                            on_press: root.show_date_picker()
                            text: "What date is it?"
                        MDRaisedButton:
                            text: "What time is it?"
                            size_hint: None, None
                            size: 3 * dp(48), dp(48)
                            on_press: root.show_time_picker()
                        MDRaisedButton:
                            id: submit_button
                            disabled: False
                            text: "Submit!"
                            size_hint: None, None
                            size: 3 * dp(48), dp(48)
                            on_press: root.submit()
                MDBottomNavigationItem:
                    name: 'info'
                    text: "Info"
                    icon: "information"
                    GridLayout:
                        spacing: 20
                        padding: 20
                        rows: 4
                        cols: 1
                        MDRaisedButton:
                            size_hint_x: 1
                        MDRaisedButton:
                            size_hint_x: 1
                        MDRaisedButton:
                            size_hint_x: 1
                        MDRaisedButton:
                            size_hint_x: 1

这对我有效尝试不将MDRaisedButton size更改为1它引发了此时钟错误,我的建议是不更改任何kivymd按钮大小提示它默认为无,而是您可以在dp中更改大小这对我有效尝试不将MDRaisedButton size更改为1它引发了此时钟错误,我的建议是不要更改任何kivymd按钮大小\u提示默认情况下没有,而是您可以更改dp中的大小

此错误仍然存在于kivymd的
MDRaisedButton
。解决此问题的一个简单解决方法是使用
size\u hint
而不是
size\u hint\u x

例如,在您的情况下,替换

MDRaisedButton:
    size_hint_x: 1


这个bug仍然存在于KivyMD的
MDRaisedButton
中。解决此问题的一个简单解决方法是使用
size\u hint
而不是
size\u hint\u x

例如,在您的情况下,替换

MDRaisedButton:
    size_hint_x: 1

MDRaisedButton:
    size_hint: 1., None