from tkinter import *
root = Tk()
canv = Canvas(bg="white")
canv.grid(columnspan=3)
nujniy_cvet = #что сюда писать чтобы получить значение цвета по координатам x=1, y=1?
print(nujniy_cvet)
root.mainloop()
from tkinter import *
root = Tk()
screen = Canvas(root)
screen.pack()
i=[]
a=0 #создаём окошко, холст, массив и т.д.
for j in "red","green","blue",'black',"white","red","green","blue",'black',"white": #создаём набор квадратиков
a+=10
i.append(screen.create_rectangle((10+a, 10+a, 30+a, 30+a), fill=j, tags=('i')))
def onmotion(event): # самое интересное
x = root.winfo_pointerx()-root.winfo_x() # получаем координаты курсора относительно окна
y = root.winfo_pointery()-root.winfo_y() #
print (screen.find_overlapping(x+0.5,y-0.5,x+0.5,y+0.5),x,y ) # выводим, какую фигуру(-ы) накрывает квадрат 1х1 пиксель
print ( screen.itemcget(screen.find_overlapping(x+0.5,y-0.5,x+0.5,y+0.5)[-1], "fill" ) ) # выводим цвет самой верхней фигуры
screen.bind("<Button-1>",onmotion) #привязываем к клику лкм функцию
root.mainloop() # запускаемся
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()