我想通过单击按钮来移动画布内的小部件。不幸的是,我总是得到相同的错误:“_tkinter.TclError:标签搜索表达式中的布尔运算符无效”
我已经隔离了错误代码:
import tkinter as tk
root = tk.Tk()
w = tk.Canvas(root, width=200, height=200)
w.pack()
def button():
w.coords(checkbutton, 0, 0, 75, 25)
test = tk.BooleanVar()
checkbutton = tk.Checkbutton(w, text="example", variable=test, width=20, anchor="w")
w.create_window((100, 100), window=checkbutton)
button = tk.Button(w, text="Click", command=button)
button.place(x=50, y=50)
root.mainloop()
我也尝试过 .configure 方法,但没有成功。
如果您有任何建议,请帮助我。
提前致谢!
coords()
的第一个参数是.create_window(...)
返回的item ID。 此外,小部件项目所需的坐标只是一个位置。
def button():
w.coords(item_id, 175, 125)
...
item_id = w.create_window((100, 100), window=checkbutton)