【发布时间】:2018-11-05 22:41:18
【问题描述】:
我不明白为什么我对下面代码中的 tag_bind 没有反应:只是想获得 tag_bind 的句柄以便稍后详细说明事件处理程序。什么都没有发生,tkinter 也没有抱怨。感谢您的帮助。
import tkinter as tk
root = tk.Tk()
size = input("Choose a grid size eg. 4, 7, 12 ...: ")
size = int(size)
def create_grid():
d = 20
x0 = 20
x1 = x0 + d
y0 = 20
y1 = y0 + d
for i in list(range(size)):
for j in list(range(size)):
row = i
col = j
id = cv.create_rectangle(x0, y0, x1, y1,
tags="ALL",fill="white")
x0 = x1
x1 += d
x0 = d
x1 = x0 + d
y0 = y1
y1 = y0 + d
id = cv.create_oval(24, 24, 36, 36, tags=("ALL","oval"),fill="yellow")
def oval_move(event):
print(event.keysym)
cv = tk.Canvas(root, bd=5, relief="groove")
cv.pack(fill="both", expand=True)
cv.bind('<Configure>', create_grid())
cv.focus_set() # probably not needed
cv.tag_bind("oval", '<KeyPress-Down>', oval_move)
root.mainloop()
【问题讨论】:
标签: object canvas tkinter tags bind