Tkinter Canvas 重置 ID

编程入门 行业动态 更新时间:2024-10-22 14:05:17
本文介绍了Tkinter Canvas 重置 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在为学校的一个高级研究项目编写 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 06:37:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390619.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Tkinter   Canvas   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!