Python kivy [CRITICAL] [Clock ]警告,下一帧之前完成的迭代太多

rkue9o1l  于 2022-11-26  发布在  Python
关注(0)|答案(1)|浏览(109)

我正在kivy中为移动设备制作一个日历应用程序,并希望为堆栈布局制作一个滚动视图,但一直收到此错误,我不知道为什么
Python代码
`

from kivymd.app import MDApp
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.stacklayout import StackLayout
from calendar import monthrange
import calendar


year = 2022
month_int = 11
num_days = monthrange(year, month_int)[1]
weekheader = str(calendar.weekheader(3))
days = weekheader.split(" ")
days_length = len(days)
month = calendar.monthcalendar(year, month_int)
print(month)
start_day = month[0].count(0)
print(start_day)


class GridLayoutExample(GridLayout):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        for l in range(2):
            label4 = Label()
            self.add_widget(label4)
        
        button2 = Button(text=str(month_int))
        self.add_widget(button2)
        button3 = Button(text=str(year))
        self.add_widget(button3)
        
        for k in range(3):
            label3 = Label()
            self.add_widget(label3)
        
        for j in range(days_length):
            label1 = Label(text=days[j], color=(0, 0, 0, 1))
            self.add_widget(label1)
        
        for g in range(start_day):
            label2 = Label()
            self.add_widget(label2)
        
        for i in range(num_days):
            button = Button(text=str(i + 1))
            button.my_id = str(i + 1) + "-" + str(month_int) + "-" + str(year)
            self.ids[str(i + 1) + "-" + str(month_int) + "-" + str(year)] = button
            self.add_widget(button)

class LayoutExample(StackLayout):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        for l in range(10):
            label4 = Label(text="zeer plezant \n \n \n ha \n haha", size = self.size, color=(0, 0, 0, 1), size_hint=(None, None))
            self.add_widget(label4)
            button = Button(text="verwijder")
            self.add_widget(button)
            button = Button(text="wijzig")
            self.add_widget(button)

class agenda1(MDApp):
    pass

agenda1().run()

`
kv文件

#:kivy 1.0
PageLayoutExample:

<PageLayoutExample@PageLayout>:
    GridLayoutExample:
    ScrollViewExample:

<ScrollViewExample@ScrollView>:
    LayoutExample:
        


<GridLayoutExample>:
    #left-right  top-bottom
    cols: 7
    orientation: "lr-tb"
    size: root.minimum_width, root.minimum_height
    padding: ("20dp", "20dp", "20dp", "20dp")

<LayoutExample>:
    cols: 1
    orientation: "lr-tb"
    padding: ("20dp", "20dp", "20dp", "20dp")
    size_hint: 1, None
    height: self.minimum_height

我在代码中做错了什么吗?
我希望scrollview能滚动到屏幕上的所有数据,但不要超过这个范围。因为我迭代了一个x数量的任务,所以我真的看不到一种减少迭代的方法。

dsekswqp

dsekswqp1#

因为您在LayoutExample中使用height: self.minimum_height,所以您必须提供其子系的明确大小。
添加到LayoutExample中的Buttons具有默认的(1,1)size_hint,因此在LayoutExample布局计算中导致无限循环。它试图计算其minimum_height,因此每个Button的高度都被设置为LayoutExample的高度。然后LayoutExample计算并应用将容纳Buttons的新的最小高度。然后Buttons将其大小更改为LayoutExample的新大小,其触发由LayoutExample对其minimum_height的新计算....
修复方法是为每个Button指定一个size,如下所示:

for l in range(10):
        label4 = Label(text="zeer plezant \n \n \n ha \n haha", size=self.size, color=(0, 0, 0, 1),
                       size_hint=(None, None))
        self.add_widget(label4)
        button = Button(text="verwijder", size_hint=(None, None), size=(100, 20))
        self.add_widget(button)
        button = Button(text="wijzig", size_hint=(None, None), size=(100, 20))
        self.add_widget(button)

相关问题