我用RelativeLayout
定位了一个相对于屏幕大小的图像。如何获取该图像的全局(/窗口)位置,以便检测触摸坐标是否与图像重叠
这是我目前的想法:
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.image import Image
from kivy.uix.relativelayout import RelativeLayout
class mainApp(App):
def build(slef):
appRoot = FloatLayout()
relPos = RelativeLayout()
button = Image()
relPos.pos_hint = {"right":1,"top":1.5}
relPos.add_widget(button)
#attempting to print the coordinates of the Image in the window
print(relPos.to_parent(*button.pos))
return relPos
if __name__ == '__main__':
mainApp().run()
如您所见,我试图使用to_parent
来获取相对于父对象的位置。然而,我认为它不起作用
我也尝试过使用AnchorLayout
,也遇到过类似的问题
注意:虽然我知道我可以使用window_size
,但我需要一个更健壮的解决方案,可以处理更复杂的情况
目前没有回答
相关问题 更多 >
编程相关推荐