如何在Kivy中获取小部件在其布局中的位置? [英] How to get a widget position inside it's layout in Kivy?
问题描述
我有一个GridLayout,添加图像后在上面添加了一些图像小部件,我想通过使用画布在每个图像中绘制一个矩形,但是我不能,因为我不知道GridLayout上确切的图像小部件位置
I have a GridLayout and I added some Image widgets on it after adding of images I want to draw a rectangle in each image by using their canvas but I couldn't because I don't know the exact Image widgets positions on GridLayout.
在我的Python代码的最后一行:Rectangle(pos = (child.x - 2.4, child.y + 467), size = (70, 70))
In last line of my Python code : Rectangle(pos = (child.x - 2.4, child.y + 467), size = (70, 70))
如何在子级中绘制此矩形(我的方法不好^),
How to draw this rectangle in child(My method is not good^),
为什么我的GridLayout设置为pos_hint = {"center_x" : .5}
后也不能居中?
Also Why my GridLayout not coming in center after setting it's pos_hint = {"center_x" : .5}
?
推荐答案
如果我理解正确的问题,请尝试使用诸如 to_parent()
, to_window()
.您也可以尝试从Widget的位置减去GridLayout的位置.
If I understand question right, try to use such methods as to_local()
, to_parent()
, to_widget()
and to_window()
. Also you could try to subtract position of your GridLayout from Widgets' positions.
这篇关于如何在Kivy中获取小部件在其布局中的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!