简体   繁体   English

Find an object that other canvas object is overlapping with - Python tkinter

[英]Find an object that other canvas object is overlapping with - Python tkinter

I want to detect with what canvas object block .我想用 canvas object block来检测。 We have block, circle and triangle canvas objects.我们有block, circle and triangle canvas 对象。

I know there is if block in canvas.find_overlapping(x1,y1,x2,y2): method but doesn't shows with what object is block overlapping.我知道if block in canvas.find_overlapping(x1,y1,x2,y2):但没有显示 object 是block重叠的内容。 It just shows if block is touching with any other canvas object.它只显示block是否与任何其他 canvas object 接触。

overlapping_object=canvas.find_overlapping(block) , overlapping_object could be a list that shows tags of objects that is block touching with. overlapping_object=canvas.find_overlapping(block)overlapping_object可以是一个列表,显示与block接触的对象的标签。

How to make overlapping_object=canvas.find_overlapping(block) but it's correct.如何制作overlapping_object=canvas.find_overlapping(block)但它是正确的。 This one I typed here is just how could it look.我在这里输入的这个只是它的外观。

Thanks for any help!谢谢你的帮助!

I'm making 2D minecraft in tkinter and this is the thing that can really speed up my process.我正在 tkinter 中制作 2D minecraft,这是可以真正加快我进程的东西。

If you're not willing to use other libraries and only tkinter, I don't think there's a built in function in tkinter that will allow it.如果您不愿意使用其他库并且只使用 tkinter,我认为 tkinter 中的内置 function 不会允许它。 I am also not sure why everything must be done in tkinter as it's not at all unusual for programs to use multiple libraries.我也不确定为什么必须在 tkinter 中完成所有操作,因为程序使用多个库并不少见。 Personally, given tikinter's limitations, I would use pygame to track polygons and their intersection but would never draw them.就个人而言,鉴于 tikinter 的局限性,我会使用 pygame 来跟踪多边形及其交叉点,但永远不会绘制它们。 Short of using a third library (tikinter, python default, and other), there is one other approach.除了使用第三个库(tikinter、python 默认等)之外,还有另一种方法。 I mean it's really the only appraoch.我的意思是这真的是唯一的方法。

good ole fashioned math.很好的老式数学。 https://algs4.cs.princeton.edu/93intersection/ Here's some documentation on how to go about doing that. https://algs4.cs.princeton.edu/93intersection/这里有一些关于如何做 go 的文档。 I wish you luck.祝你好运。

Wait no I wanted to comment but I dont have 50 rep yet.等等,不,我想发表评论,但我还没有 50 个代表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM