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])
r = random.randint(0,8)
matrix[r] = 2
if matrix[r] == 2:
canvas.create_rectangle(xy[r*2],xy[r*2+1],xy[r*2]+90,xy[r*2+1]+90, outline="#f11", fill="#111", width=2)
#matrix[index] = 2
#if matrix[index] == 2:
#canvas.create_rectangle(it_1,it_2, it_1+90,it_2+90, outline="#f11", fill="#111", 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]
root.mainloop()
|