【发布时间】:2020-10-04 21:04:38
【问题描述】:
我是 GUI 开发的新手,我正在使用 Kivy 做同样的事情。我在屏幕顶部制作了一个rectangle,它随着窗口大小的变化而增加/减少其长度。我想在矩形内添加文本,这样当我更改窗口大小时,文本不仅会增加/减小其字体大小,而且还会留在矩形内,即在中间。我不知道如何设置font 和position 参数来实现我的目标。
这是 Myapp.py 文件代码:
class Dashboard(RelativeLayout):
l = NumericProperty(0.0)
b = NumericProperty(0.0)
class MyApp(App):
def build(self):
return (Dashboard())
MyApp().run()
这是我的.kv 文件代码:
<Dashboard>:
l: root.width
b: root.height/7
# creating Canvas
canvas:
Color:
rgba: 216 / 255., 195 / 255., 88 / 255., 1
Rectangle:
pos: (0,self.size[1]/1.15)
size: (self.l,self.b)
Label:
size: self.parent.size[0], self.parent.size[1]
font_size: self.parent.size[0] * 0.05
text_size: self.size
pos_hint: {'x':0.5,'y':0.9}
text:'hello!'
提前致谢! :)
【问题讨论】: