我正在尝试将标签称为" number"直接显示在椭圆的中心。我已经尝试在AnchorLayouts和RelativeLayouts中以相同的布局,不同的布局放置它们,但我还没有能够弄清楚如何使用它。
这是我的python的测试版本,显示了同样的问题:
class BugTester(FloatLayout):
def __init__(self):
super().__init__()
for i in range(1,6):
temp = GamePiece(5, "Red")
temp.pos = (i*100,i*200)
self.add_widget(temp)
class BugTestingApp(App):
def build(self):
return BugTester()
class GamePiece(ToggleButton):
def __init__(self, number, color, **kwargs):
self.number = number
self.player_color = color
self.background_normal = "5.png"
super(GamePiece, self).__init__()
if __name__ == '__main__':
BugTestingApp().run()
我的小事:
<BugTester>:
Button:
background_disabled_normal: "background.jpg"
disabled: True
<GamePiece>:
id: gamepiece
size_hint:(None, None)
group: self.player_color
border: (0,0,0,0)
AnchorLayout:
id: layout
center: root.center
on_size: self.size = root.size
anchor_x: "left"
anchor_y: "bottom"
canvas:
Color:
rgba: 0,0,0,1
Ellipse:
#this is the ellipse in question
id: circle
size: (root.width/2.5, root.height/3)
#pos: -15, -20
pos: root.pos
Label:
#this is the label I want centered over the ellipse
id: number
text: str(root.number)
color: (1,1,1,1)
font_size: root.height/4
bold: True
#pos: root.pos
答案 0 :(得分:2)
在您的示例中,标签与它们所属的锚布局一样大,因此您无法移动它们。
如果您希望它们具有其他大小,请禁用size_hint
,并使用固定的size
(例如,与省略号一样大):
Label:
#this is the label I want centered over the ellipse
size_hint: None, None
size: (root.width/2.5, root.height/3)
id: number
text: str(root.number)
color: (1,1,1,1)
font_size: root.height/4
bold: True
#pos: root.pos
结果: