我注意到,当您在 Kivy 中使用网格布局制作按钮时,它们会在 (0,0) 处创建,并根据先前按钮的长度和宽度移动多个空格。但是,我想在屏幕底部的中间有一个 3x4 网格。
到目前为止我有这个:
import kivy
from kivy.uix.gridlayout import GridLayout
from kivy.app import App
from kivy.uix.button import Button
class CalcApp(App):
def build(self):
layout = GridLayout(cols=3, row_force_default=True, row_default_height=50)
layout.add_widget(Button(text='1', size_hint_x=None, width=100))
layout.add_widget(Button(text='2', size_hint_x=None, width=100))
layout.add_widget(Button(text='3', size_hint_x=None, width=100))
layout.add_widget(Button(text='4', size_hint_x=None, width=100))
layout.add_widget(Button(text='5', size_hint_x=None, width=100))
layout.add_widget(Button(text='2', size_hint_x=None, width=100))
layout.add_widget(Button(text='6', size_hint_x=None, width=100))
layout.add_widget(Button(text='7', size_hint_x=None, width=100))
layout.add_widget(Button(text='8', size_hint_x=None, width=100))
layout.add_widget(Button(text='9', size_hint_x=None, width=100))
layout.add_widget(Button(text='0', size_hint_x=None, width=100))
layout.add_widget(Button(text='Enter', size_hint_x=None, width=100))
return layout
CalcApp().run()
那么,如何转移位置呢?