Snapping to pixels in wxpython

微笑、不失礼 提交于 2019-12-11 08:48:10

问题


I am creating a simple GUI to record points which are clicked on the image, using wxpython. However, i would like the click to be snapped to certain points on the image. Please suggest methods.


回答1:


The easiest to snap to a fixed scale grid is with something like:

snap_x = scale * round(x / scale)
snap_y = scale * round(y / scale)

where scale is the size of your grid, eg 10 pixels.

If the points are nonuniformly distributed, then find the closest based on the distance (or the square of the distance for efficiency reasons).




回答2:


You might have a look at wxPython's Object Graphics Library. The documentation's a little sparse but the Diagram class has direct support for snapping to grids; take a look at the wxPython Demo's Miscellaneous->OGL section for some ideas to get started. I'm in the middle of a project w. OGL right now - it's great for what it does but like I said I find the documentation a little thin.



来源:https://stackoverflow.com/questions/7794496/snapping-to-pixels-in-wxpython

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!