【发布时间】:2022-12-01 01:14:33
【问题描述】:
我正在尝试使用 Kivy 在 Python 中设计一个界面。我需要以精确的方案将小部件添加到我的应用程序,比方说一个有两行三列的网格。我不会在所有六个位置添加小部件。我不确定GridLayout是最合适的,所以我开始修改一个更复杂的layout。
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
Builder.load_string("""
<Boxes>:
AnchorLayout:
anchor_x: 'center'
anchor_y: 'top'
BoxLayout:
orientation: 'vertical'
padding: 20
BoxLayout:
orientation: 'horizontal'
Button:
text: "1"
Button:
text: "2"
Button:
text: "3"
BoxLayout:
orientation: 'horizontal'
Button:
text: "4"
Button:
text: "6" """)
class Boxes(FloatLayout):
pass
class TestApp(App):
def build(self):
return Boxes()
if __name__ == '__main__':
TestApp().run()
此代码生成此布局:
我想在第二行的第一列中放置按钮“4”,在第二行的第三列中放置按钮“6”,从而为当前未添加的另一个按钮留出空间。按钮“4”和“6”应分别与按钮“1”和“3”对齐。有什么建议吗?对于不规则的网格方案,哪种布局最合适?有没有办法在 Kivy 网格布局中添加小部件,指定它们在行和列中的位置?
【问题讨论】:
标签: python user-interface layout kivy