Tkinter Canvas 重置 ID [英] Tkinter Canvas reset ID's

查看:37
本文介绍了Tkinter Canvas 重置 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为学校的一个高级研究项目编写 Tkinter GUI.

I am coding a Tkinter GUI for a senior research project at school.

我需要在代码中的某个点重置用于为新添加的内容创建 id 值的计数器.有谁知道除了更换整个画布之外是否还有可能?基本上,在添加了一堆线条和椭圆之后,我需要将它们全部删除,并在 1 处重新启动计数器以获取新的.

I need to, at some point in the code, reset the counter used to create id values for new additions. Does anyone know if this is possible beside replacing the entire canvas? Basically, after adding a bunch of lines and ovals, I need to delete them all and restart the counter at 1 for new ones.

其次,我采取了替换整个画布的方法,之后,winfo_get() 方法中没有任何显示.为什么会这样?我知道我正在尝试做一些 TKinter 不应该做的事情,但它必须是可能的.

Second, I have taken the path of replacing the entire canvas, and afterwards, nothing EVER shows up in the winfo_get() method. Why could this be? I know I'm trying to do something that TKinter isn't supposed to do, but it must be possible.

推荐答案

无法重置画布生成的 ID 编号.

It is not possible to reset the id numbers generated by a canvas.

您删除和重新创建画布的解决方案是一个合理的选择,尽管它可能不是必需的.可能有更好的方法可以通过重置画布 ID 来解决您认为可以解决的任何问题.例如,您可以生成自己的 id,并将每个 id 与每个画布项目关联为一个标签.然后,您可以随时重置 ID.

Your solution of deleting and recreating the canvas is a reasonable alternative, though it may not be necessary. There are probably better ways to do whatever it is you think is solved by resetting canvas ids. For example, you could generate your own ids, and associate each id with each canvas item as a tag. You can then reset the ids any time you want.

这篇关于Tkinter Canvas 重置 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆