Python在鼠标点击时改变了specefic网格框的颜色

时间:2018-06-09 04:24:13

标签: python tkinter grid tkinter-canvas

我在tkinter canvas中创建了网格图像。如何在鼠标点击事件中更改网格的specefic框的颜色。如果用户在specefic框中单击任意位置,则应更改该框颜色。怎么做。这是代码。

# Input image
img = Image.open("inputimage.png")   # input image
# Draw grid over image
step_count = 50
draw = ImageDraw.Draw(img)
y_start = 0
y_end = img.height
step_size = int(img.width / step_count)

for x in range(0, img.width, step_size):
    line = ((x, y_start), (x, y_end))
    draw.rectangle(line, fill="black")

x_start = 0
x_end = img.width

for y in range(0, img.height, step_size):
    line = ((x_start, y), (x_end, y))
    draw.rectangle(((x_start,y), (x_end, y)), fill="black")

0 个答案:

没有答案