from tkinter import *
root = Tk()
screen = Canvas(root,width=504, height=504)
screen.grid(row=0, column=0)
screen.create_rectangle((0, 0, 504, 504),fill="white")
step = 36
def click(event):
screen.create_oval((event.x, event.y, event.x+step, event.y+step), width=0, fill='black')
xp = event.x
yp = event.y
xp = str(xp)+'\n'
yp = str(yp)
f = open('tt.txt','w')
xp = f.write(xp)
yp = f.write(yp)
f.close
screen.bind("<B1-Motion>", draw)
def onmotion(event):
x = event.x
y = event.y
a = []
temp = 18
p = temp//2
for j in range(0, 504, temp):
for i in range(0, 504, temp):
if screen.itemcget(screen.find_overlapping(i+p,j+p,i+p,j+p)[-1], "fill" ) != 'black':
a.append(0)
else:
a.append(1)
f1 = open("arr.txt", 'w')
f1.write(str(a))
f1.close
def draw(event):
f = open(r'tt.txt')
xp = f.readlines()
xp[0] = int(xp[0])+step/2
xp[1] = int(xp[1])+step/2
f.close
screen.create_oval((event.x, event.y, event.x+step, event.y+step), width=0, fill='black')
screen.create_line(xp[0], xp[1], event.x+step/2, event.y+step/2,width=step, fill='black')
xp = event.x
yp = event.y
xp = str(xp)+'\n'
yp = str(yp)
f = open('tt.txt','w')
xp = f.write(xp)
yp = f.write(yp)
f.close
screen.bind("<Motion>", onmotion)
screen.bind("<Button-1>",click)
root.mainloop()