2

I want to use kivy scatter in order to resize the widgets which scatter contains. So, I created box_total contained in scatter, contained in floatlayout.

This is the code:

from kivy.app import App

from kivy.uix.scatter import Scatter
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button

class TutorialApp(App):
    def build(self):
        b = BoxLayout(orientation='vertical')
        button = Button(text = 'something')
        b.add_widget(button)


        box_labels = BoxLayout(orientation = 'horizontal')
        label1 = Label(text = 'hello')
        box_labels.add_widget(label1)
        label2 = Label(text = 'world')
        box_labels.add_widget(label2)

        box_buttons = BoxLayout(orientation = 'horizontal')
        button1 = Button(text = 'hello')
        box_buttons.add_widget(button1)
        button2 = Button(text = 'world')
        box_buttons.add_widget(button2)

        box_total = BoxLayout(orientation = 'vertical')
        box_total.add_widget(box_labels)
        box_total.add_widget(box_buttons)


        f = FloatLayout()
        s = Scatter()
        f.add_widget(s)        
        s.add_widget(box_total)
        b.add_widget(f)

        return b

if __name__ == "__main__":
    TutorialApp().run()

and this is what I get:

enter image description here

How can I resize the inner widget box_total in order to occupy the whole FloatLayout area? (the bottom half of the window)

user3060854
  • 923
  • 2
  • 15
  • 25

1 Answers1

2

Scatter isn't a layout, therefore the automatical setting of the position won't work here. Use ScatterLayout to behava like both a Scatter and a FloatLayout.

from kivy.uix.scatterlayout import ScatterLayout
ScatterLayout()

Or do that manually with setting the positions of the widgets inside the FloatLayout, but remember you'll need to do size_hint=(None, None) first.

Peter Badida
  • 11,310
  • 10
  • 44
  • 90