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)
if matrix[index] == 1:
matrix[index] = 2
r = 0
while True:
r = random.randint(0,8)
if (matrix[r] == 1):
matrix[r] = 3
break
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[r] == 3:
canvas.create_rectangle(xy[r*2],xy[r*2+1],xy[r*2]+90,xy[r*2+1]+90, outline="#f11", fill="#999", width=2)
global click
click = click + 1
for i in range(0,8):
if (matrix[i] == 1 and click == 4):
canvas.create_rectangle(xy[i*2],xy[i*2+1],xy[i*2]+90,xy[i*2+1]+90, outline="#f11", fill="#ff55ff", width=2)
print(str(xy[i*2])+" "+str(xy[i*2+1]))
print("*************")
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 = 0
root.mainloop()
|