Search code examples
pythonkivy

how to set width to self.minimun_width of the boxlayout widget into py file not kv file


i need to set the width for boxlayout widget to minimun_width to use it into scrollview what is the wrong in this code ?

BoxLayout(size_hint_x=None , width=self.minimum_width)

Solution

  • You need binding. Try it like,

    box = BoxLayout(size_hint_x=None)
    box.bind(minimum_width=box.setter("width"))
    

    This (binding) will automatically set (by using default callback setter) the width of the box to its minimum_width whenever a widget of fixed width is added to it.