python - 2 BoxLayout 中的 FloatLayouts 格式不正确
问题描述
我是 Kivy 的新手,正在开发 UI 以使一组相当复杂的小部件正确显示。我的根小部件是一个 boxlayout(horiz),我试图让 2 个浮动布局并排出现。但是第二个浮动布局显示在第一个浮动布局的 boxlayout 的左侧。我在浮动布局级别尝试使用和不使用 pos_hints 和 size_hints,但无济于事。一些基本代码:
<BoxLayout>:
id: rootwid
orientation: 'horizontal'
FloatLayout:
id: leftside
pos_hint: {'x':0, 'y':0} (Also tried 'right' and 'top' and commenting out the line)
#size_hint: (.5, 1)
(Buttons & Labels here, which lay out properly within the floatlayout)
FloatLayout:
id: rightside
pos_hint: {'x': .5, 'y':0} (Also tried 'right' and 'top' and commenting out the line)
#size_hint: (.5, 1)
(Buttons & Labels here, which lay out properly within the floatlayout)
我错过了什么?谢谢!
解决方案
除非您将来使用 FloatLayouts,否则我建议您将它们替换为其他类型的布局 bcoz,因为它们是浮动的,它们往往独立于父级。
尝试使用 GridLayout 来容纳按钮和标签以及其他像这样的小部件;
BoxLayout:
orientation: 'horizontal'
GridLayout:
cols: any
rows: any
# Left widgets added here
GridLayout:
cols: any
rows: any
# Right widgets added here
您也可以相应地嵌套它们,以扩展对这些运行KivyCatalog的洞察力,这是 kivy-examples 中的一个内置 python 文件,我认为
通常在 ~/.local/share/kivy-examples/demo/kivycatalog/main.py 对于
Windows的 Ubuntu检查 AppData 然后本地然后共享,默认情况下 AppData 是隐藏的,不要忘记这一点。
KivyCatalog 是交互式的,因为它会在您编写 kv 代码时显示您的更改,试试吧。
推荐阅读
- python - python dash 回调动态生成的搜索结果。一定有更好的方法
- sql - 如何在 Oracle IDE 中获取查询执行计划?
- java - 一次调用即可命中多个 REST 端点
- javascript - 使用 React useState 的意外行为,非常奇怪的输出
- android - gitlab-ci.yml 中的 Android 模板因共享跑步者而失败
- java - 是否可以修改在远程服务器上作为 Spring 组件运行的 Clojure 代码并使用 REPL 下载修改后的代码?
- java - Thymeleaf 片段不渲染
- django - 检查django的约束
- javascript - 如何通过 google apps-script 制作这个翻译功能代码?
- android - 与 Mqtt 连接时面临的问题