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 布局高度以适应子小部件的高度
基础教程推荐
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
