每次用鼠标按屏幕时,我都有添加和显示图片的问题。你知道吗
class Myszka(ClickAndGo, Widget):
def on_touch_down(self, touch):
super().build()
flaga_path = os.path.join(self.img_path, "test.png")
x, y = touch.pos
self.flaga = Image(source=flaga_path, size_hint=(None, None), size=(64, 64),
pos=(round(x, 1), round(y, 1)))
self.camlayout.add_widget(self.flaga)
print(touch.pos)
问题
根本原因
图像未显示,因为它正在添加到
class Myszka()
的方法on_touch_down()
中的局部属性self.camlayout
。你知道吗解决方案
用
App.get_running_app().root.add_widget(self.flaga)
替换self.camlayout.add_widget(self.flaga)
,即获取根的实例(camlayout
)。你知道吗代码段-py
示例
下面的示例演示如何在鼠标单击
FloatLayout
的位置添加Image
。你知道吗你知道吗主.py你知道吗
输出
@ikolim公司
相关问题 更多 >
编程相关推荐