How to get a widget position inside it#39;s layout in Kivy?(如何在 Kivy 的布局中获取小部件位置?)
问题描述
我有一个 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))
如何在child中绘制这个矩形(我的方法不好^),
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_local()
, to_parent()
, to_widget()
和to_window()代码>.您也可以尝试从小部件的位置中减去 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 的布局中获取小部件位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Kivy 的布局中获取小部件位置?


基础教程推荐
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 筛选NumPy数组 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01