Kivy Layout height to adapt to child widgets#39;s height(Kivy 布局高度以适应子小部件的高度)
问题描述
我想创建一个布局,其中我有类似于 BoxLayout 的东西,让我能够在我的布局中创建行",并且在每个行"中我想使用另一种 BoxLayout 中的东西来创建列".
I want to create a layout where I have something similar to a BoxLayout to give me the ability to create "rows" in my layout, and in each "row" I want to use something in the sorts of another BoxLayout to create "columns".
列不需要均匀分布.例如,我想创建一个 BoxLayout,其中一列是方形图像,另一列占据剩余的可用宽度.
The columns don't need to be evenly distributed. For example, I want to create a BoxLayout with one column with a square image, and another occupying the rest of the available width.
在我的 gist 上查看代码和屏幕截图:https://gist.github.com/MichaelGradek/e5c50038b947352d9e79
See code and screenshot on my gist: https://gist.github.com/MichaelGradek/e5c50038b947352d9e79
我已经在上面的代码中完成了基本结构,但除此之外,我希望 BoxLayout 的高度适应孩子的高度.
I have the basic structure done in the code above, but in addition, I want the BoxLayout's height to adapt to the height of the children.
实现这一目标的最佳方法是什么?
What would be the best approach to achieve this?
谢谢!
推荐答案
不要使用 BoxLayout,使用 height: self.minimum_height
的 GridLayout,并手动设置尺寸(每个子小部件的 size_hint_y: None
和 height: some_number
).
Don't use a BoxLayout, use a GridLayout with height: self.minimum_height
, and set a manual size (size_hint_y: None
and height: some_number
) for each child widget.
这篇关于Kivy 布局高度以适应子小部件的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Kivy 布局高度以适应子小部件的高度


基础教程推荐
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01