When trying to make variable columns in kivy only one column appears

When I try to make a week view with each week having it’s own column that has a variable number of values, somehow the line with the longest amount of values is the only one that appears. What am I doing wrong?

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

This is what it looks like: enter image description here

Answer

The problem is caused by the following line:

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

remove it and you will get the following:

enter image description here

Leave a Reply

Your email address will not be published. Required fields are marked *