首页 > 解决方案 > 在滚动视图中将 minimum_height 绑定到 boxlayout 时出现键错误

问题描述

如何在 python 端的 ScrollView 中将 minimum_height 绑定到 BoxLayout?

这就是我所在的位置:

class BrokenScreen(screen):

    def __init__(self, **kwargs):
        super(BrokenScreen,self).__init__(**kwargs)

        # build widgets
        self.pop = Popup(auto_dismiss=False,size=(.8,.8))
        self.box = BoxLayout(orientation='vertical', size_hint_y=None)
        self.scroll = ScrollView()

        # bind height, this is the line bringing about the error
        self.box.bind(minimum_height=self.box.setter('height'))

        # integrate
        self.scroll.add_widget(self.box)
        self.pop.add_widget(self.scroll)

当我尝试编译时,我收到以下错误:

KeyError: 'minimum_height'

做什么?

标签: pythonkivy

解决方案


Miket25 问是否boxminimum_height争论。

我能够通过使用 GridLayout 来解决我的问题。所以,可能不是(编辑:我是否错了boxhas minimum_height,请参阅接受的回复)。

    # build widgets
    self.pop = Popup(auto_dismiss=False,size=(.8,.8))
    self.grid = GridLayout(cols=1, size_hint_y=None) #<- change this
    self.scroll = ScrollView(size=self.size)

    # bind height, this is the line bringing about the error
    self.grid.bind(minimum_height=self.grid.setter('height')) # only changed var name

    # integrate
    self.scroll.add_widget(self.grid) # changed var name
    self.pop.add_widget(self.scroll)

推荐阅读