2 BoxLayout 中的 FloatLayouts 格式不正确
2 FloatLayouts in BoxLayout not formatting correctly
我是 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 for Ubuntu
对于 windows 我想先检查 AppData 然后本地然后共享,AppData 默认是隐藏的,不要忘记这一点。
KivyCatalog 是交互式的,因为它会显示您在编写 kv 代码时所做的更改,请尝试一下。
我是 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 for Ubuntu
对于 windows 我想先检查 AppData 然后本地然后共享,AppData 默认是隐藏的,不要忘记这一点。
KivyCatalog 是交互式的,因为它会显示您在编写 kv 代码时所做的更改,请尝试一下。