这是我的kivy应用的截图。我想让左下角的
TextInput
在它所在的BoxLayout
中居中,而且我不希望它与布局大小相同,我想要它小得多。这个BoxLayout
位于屏幕的下半部分。我尝试设置TextInput
的属性center:self.parent.center
,但这并没有起作用。您可以看到,我已经使用那条线,self.parent.center,将BoxLayout
中心坐标打印到了TextInput
中,并得到了正确的结果。然而,将TextInput
的中心或位置设置为这些坐标并不能使它居中,它没有移动……我做错了什么?
py文件:
import kivy
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
class TimeTabler(Widget):
pass
class TimerApp(App):
def build(self):
return TimeTabler()
if __name__ == "__main__":
TimerApp().run()
****kv文件:****
#:kivy 1.0
BoxLayout:
orientation: 'vertical'
size: root.size
BoxLayout:
orientation: 'vertical'
Label:
text: 'TimeTabler'
BoxLayout:
TextInput:
text: '%s' % (self.parent.center) # why does this work here
size_hint: None, None
width: sp(200)
height: sp(30)
center: self.parent.center # but not here