【问题标题】:How can I get object from its unique id in Tkinter?如何从 Tkinter 中的唯一 ID 获取对象?
【发布时间】:2018-10-26 15:49:29
【问题描述】:
canvas=Canvas(...)
unique_id=canvas.create_rectangle(...)
unique_id.tag_bind(...)

我收到这个错误是因为它是一个整数

AttributeError: 'int' object has no attribute 'tag_bind'

我需要得到对象

【问题讨论】:

  • 画布项目实际上不是对象;整数ID就是你得到的全部。您可以通过调用 Canvas 本身的方法来处理它们,将这些 ID 作为参数传递。
  • 谢谢。我应该如何为这个特定的矩形调用 tag_bind?

标签: python tkinter tkinter-canvas tkinter-layout


【解决方案1】:

您需要在下面将 tag_bind 与画布项目一起使用。

canvas=Canvas(...)
unique_id=canvas.create_rectangle(...)
canvas.tag_bind(unique_id,...)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多