我有一个 kv 语言的标签背景图像,但在 python 中重新编辑它,为我的标签添加 HoverBehavior 属性。曾是:<RockLayout>canvas: Rectangle: pos: self.pos size: self.size source: 'data/images/gui_elements/rock_label.png'变成:class RockLayout(FloatLayout, HoverBehavior): # BoxLayoutdef __init__(self, widget, **kwargs): super().__init__(**kwargs) widget.size_hint = (.8, .8) widget.pos_hint = ({'center_x': .5, 'center_y': .52}) self.add_widget(widget) with self.canvas.before: Rectangle(source='data/images/gui_elements/rock_label.png', pos=self.pos, size=self.size)def on_enter(self, *args): self.canvas.before.clear() with self.canvas.before: Rectangle(source='data/images/gui_elements/rock_label_hover.png', pos=self.pos, size=self.size)def on_leave(self, *args): self.canvas.before.clear() with self.canvas.before: Rectangle(source='data/images/gui_elements/rock_label.png', pos=self.pos, size=self.size)这导致canvas.before中的self.pos在初始化时不会更新,并且self.pos等于 0。当我调整窗口大小时,图像的位置不会改变。如何在 python 中而不是 .kv 语言中声明背景图像?现在就发生了当我调整窗口大小时 self.pos 没有更新我需要得到什么如何在python中正确使用kivylayuot背景图像?
1 回答
慕田峪4524236
TA贡献1875条经验 获得超5个赞
def on_size(self, *args): self.bg.size = self.size self.bg.pos = self.pos
添加回答
举报
0/150
提交
取消