【问题标题】:Kivy grid layout's minimum_height is 0Kivy 网格布局的 minimum_height 为 0
【发布时间】:2020-09-12 11:10:38
【问题描述】:

所以我是 kivy 的新手,我正在尝试使按钮列表可滚动。问题是我无法让滚动视图工作,然后我偶然发现了Kivy ScrollView - Not Scrolling。当我将它添加到我的代码中时,它仍然无法正常工作。然后我尝试打印 minimum_height 并且无论有多少按钮它总是打印 0...

这是代码(确实写得很糟糕,但这只是为了测试目的,我可能会在管理滚动时重写它):

    def on_pre_enter(self, *args):
        mainLayout = RelativeLayout()
        self.add_widget(mainLayout)
        scroll = ScrollView(do_scroll_x = False)
        infoLayout = GridLayout(cols = 1, size_hint = (0.5, None), pos_hint={"top":0.8,"center_x":0.5})
        mainLayout.add_widget(scroll)
        scroll.add_widget(infoLayout)

        InfoWidgetButton = Button(text='Hello world', font_size=14, size_hint=(0.5, None), height = 30, pos_hint={"top":0.8,"center_x":0.5}, on_release= lambda x:self.buttonPress(infoLayout))
        infoLayout.add_widget(InfoWidgetButton)
        InfoWidgetButton = Button(text='Hello world', font_size=14, size_hint=(0.5, None), height=30,
                                  pos_hint={"top": 0.8, "center_x": 0.5},
                                  on_release=lambda x: self.buttonPress(infoLayout))
        infoLayout.add_widget(InfoWidgetButton)
        InfoWidgetButton = Button(text='Hello world', font_size=14, size_hint=(0.5, None), height=30,
                                  pos_hint={"top": 0.8, "center_x": 0.5},
                                  on_release=lambda x: self.buttonPress(infoLayout))
        infoLayout.add_widget(InfoWidgetButton)
        InfoWidgetButton = Button(text='Hello world', font_size=14, size_hint=(0.5, None), height=30,
                                  pos_hint={"top": 0.8, "center_x": 0.5},
                                  on_release=lambda x: self.buttonPress(infoLayout))
        infoLayout.add_widget(InfoWidgetButton)
        InfoWidgetButton = Button(text='Hello world', font_size=14, size_hint=(0.5, None), height=30,
                                  pos_hint={"top": 0.8, "center_x": 0.5},
                                  on_release=lambda x: self.buttonPress(infoLayout))
        infoLayout.add_widget(InfoWidgetButton)
        InfoWidgetButton = Button(text='Hello world', font_size=14, size_hint=(0.5, None), height=30,
                                  pos_hint={"top": 0.8, "center_x": 0.5},
                                  on_release=lambda x: self.buttonPress(infoLayout))
        infoLayout.add_widget(InfoWidgetButton)
        InfoWidgetButton = Button(text='Hello world', font_size=14, size_hint=(0.5, None), height=30,
                                  pos_hint={"top": 0.8, "center_x": 0.5},
                                  on_release=lambda x: self.buttonPress(infoLayout))
        infoLayout.add_widget(InfoWidgetButton)
        infoLayout.height = infoLayout.minimum_height
        print(infoLayout.minimum_height)

【问题讨论】:

  • 在你打印它的时候它是 0,它可能在所有回调都运行后的下一帧不是 0

标签: python python-3.x kivy


【解决方案1】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-04
    • 2013-03-08
    • 2016-03-26
    • 2018-04-11
    • 1970-01-01
    • 1970-01-01
    • 2011-10-28
    • 2013-04-24
    相关资源
    最近更新 更多