尝试在kivy中创建变量列时,只显示一列

时间:2018-02-19 23:46:45

标签: python kivy

当我尝试使用具有可变数量值的自己的列的每周进行一周视图时,不知何故具有最长值的行是唯一出现的行。我做错了什么?

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button


class TestApp(App):
    def build(self):
        print("run main")
        weeklyView = GridLayout(cols=7)
        weeklyTasks= [[],[1,2,3,4,5],[1,2,3,4,5,6,7,8,9,10,11,12,13],[],[1,2,3,4,5],[1,2,3],[]]
        for dayOfWeek in range(0,7):
            print(dayOfWeek)
            filteredTasks= weeklyTasks[dayOfWeek]
            dayLayout = GridLayout(cols = 1,row_force_default=True, row_default_height=100, size_hint_y=None);
            dayLayout.bind(minimum_height=dayLayout.setter('height'))
            header = Button(text='day')
            print('add header')
            dayLayout.add_widget(header)
            for task in filteredTasks:
                label = Button(text= str(task))
                print(task)
                label.text_size = label.size
                dayLayout.add_widget(label)
            weeklyView.add_widget(dayLayout)
        mainLayout = BoxLayout()
        mainLayout.add_widget(weeklyView)
        return mainLayout

if __name__ == '__main__':

    TestApp().run()

这就是它的样子: enter image description here

1 个答案:

答案 0 :(得分:0)

问题是由以下行引起的:

dayLayout.bind(minimum_height=dayLayout.setter('height'))

将其删除,您将获得以下内容:

enter image description here