【发布时间】:2019-11-03 12:35:17
【问题描述】:
如果我将画布项目存储在一个变量中,我希望该变量存储为一个 tkinter.rectangle 对象,我以后可以使用它。
rec = can.create_rectangle(l, fill="blue")
而是存储为整数>
from tkinter import Tk, Canvas, Button
def press(canv, rect):
print("pressed")
canv.move(rect, 10)
l = [50,100,100,200]
root = Tk()
can = Canvas(root)
can.pack()
rec = can.create_rectangle(l, fill="blue")
print("rec",rec) #1
print("type(rec) ", type(rec)) #<class 'int'>
b = Button(root, text="NOTHING", command=lambda:press(can, rec))
b.pack()
print("type(b) = ",type(b)) #<class 'tkinter.Button'>
print("b = ",b) #TCL id like .41549040
root.mainloop()
运行此代码时会返回错误:
_tkinter.TclError: wrong # args: should be ".21823184 move tagOrId xAmount yAmount"
为什么它是整数类型以及如何获取画布项的 id 以便以后移动它?
【问题讨论】:
-
_tkinter.TclError: wrong # args::你误会了,这与rec无关。阅读Tkinter.Canvas.move-method的参数 -
那是什么意思它不是关于rec?
-
_tkinter.TclError:不是关于rec它是关于缺少参数x_move和y_move -
好的,现在我明白了,谢谢