【发布时间】:2020-04-12 07:42:14
【问题描述】:
试图将文本放置在 Rectangle 中。我什至尝试了给定here 的解决方案。 我希望文本在矩形内。即使我请更改窗口大小,这也应该很好。当我添加_widget Actor 时,我仍然想继续 pos_hint 和 size_hint 格式。请有什么想法..
from kivy.uix.label import Label
from kivy.uix.relativelayout import RelativeLayout
from kivy.properties import ListProperty
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.scatter import Scatter
from kivy.core.window import Window
Window.clearcolor = (1, 1, 1, 1)
Window.size = (800, 600)
kv = '''
<Actor>:
canvas:
PushMatrix
Color:
rgba: 0,1,0,.8
Rectangle:
id: _rect_
size: self.width, self.height/12
pos: 0, 11 * (self.height / 12)
Line:
points: self.width/2, 11 * self.height/12, self.width/2, 0
width:2
PopMatrix
Label:
id: _actr_lbl
text: 'Hello World'
markup: True
color: 0,0,0,1
pos: 0, 11 * self.height/12
halign: 'center'
'''
Builder.load_string(kv)
class Actor(Scatter):
def __init__(self, **kwargs) :
super(Actor, self).__init__(**kwargs)
class TestApp(App):
def build(self):
layout = RelativeLayout()
layout.add_widget(Actor(pos_hint = {'center_x':0.5, 'top':0.95}, size_hint = (0.2, 1)))
return layout
if __name__ == '__main__':
TestApp().run()
【问题讨论】: