在kivy scatter

时间:2016-10-23 09:20:58

标签: python kivy scatter

我想使用kivy scatter来调整散布包含的小部件的大小。因此,我创建了box_total中包含的scatter floatlayout

这是代码:

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

这就是我得到的:

enter image description here

如何调整内部窗口小部件box_total的大小以占用整个FloatLayout区域? (窗口的下半部分)

1 个答案:

答案 0 :(得分:2)

Scatter不是布局,因此位置的自动设置在此处不起作用。使用ScatterLayout可以像ScatterFloatLayout一样行事。

from kivy.uix.scatterlayout import ScatterLayout
ScatterLayout()

或者通过在FloatLayout内设置小部件的位置来手动执行此操作,但请记住,您需要先size_hint=(None, None)