from tkinter import *
import random
def mouse1(event):
global canvas,matrix
it_1 = event.x//100 * 100
it_2 = event.y//100 * 100
index = 0
if event.x//100 == 0:
index = event.x//100 + event.y//100
if event.x//100 == 1:
index = event.x//100 + event.y//100 + 2
if event.x//100 == 2:
index = event.x//100 + event.y//100 + 4
xy = []
for it1 in range(0,300,100):
for it2 in range(0,300,100):
xy.append(it1)
xy.append(it2)
for it1 in range(0,len(xy)):
print(xy[it1])
global click
if matrix[index] == 1 and click == 10:
click = 20
matrix[index] = 2
elif matrix[index] == 1:
matrix[index] = 3
click = 10
if matrix[index] == 2:
canvas.create_rectangle(xy[index*2],xy[index*2+1],xy[index*2]+90,xy[index*2+1]+90, outline="#f11", fill="#111", width=2)
if matrix[index] == 3:
canvas.create_rectangle(it_1,it_2, it_1+90,it_2+90, outline="#f11", fill="#fff", width=2)
root = Tk()
root.geometry("500x500")
root.bind('<Button-1>', mouse1)
canvas = Canvas(root, width = 500, height = 500)
canvas.place(x = 0 ,y = 0)
for it_1 in range(0,300,100):
for it_2 in range(0,300,100):
canvas.create_rectangle(it_1,it_2, it_1+90,it_2+90, outline="#f11", fill="#1f1", width=2)
matrix = [1,1,1,1,1,1,1,1,1]
click = 10
root.mainloop()
|