주황색 원을 포함하는 자주색 사각형 안에 부분적으로 새겨진 빨간 별이 있습니다. 사용자가 클릭하는 지점의 색을 추출 중입니다. 사각형 안의 원을 클릭하면 반환되는 색상은 주황색이 아닌 자주색입니다. 광장 안쪽에있는 빨간 별 부분을 클릭하면 프로그램이 자주 나타납니다. 이 문제를 어떻게 해결할 수 있습니까? 고맙습니다.거북이 그래픽 - 겹치는 도형의 색 검색
import turtle
def border(height,color):
height = float(height)
length = height *(1.9)
length = round(length,2)
# Draws a rectangle.
turtle.begin_fill()
turtle.color(color)
turtle.down()
turtle.forward(length)
turtle.right(90)
turtle.forward(height)
turtle.right(90)
turtle.forward(length)
turtle.right(90)
turtle.forward(height)
turtle.right(90)
turtle.end_fill()
def big_shape(vertices, steps, length):
turtle.color("red")
turtle.begin_fill()
for i in range(vertices):
turtle.forward(length)
turtle.right(steps*360.0/vertices)
turtle.end_fill()
def textbox_click(rawx,rawy):
turtle.up()
turtle.setposition(rawx,rawy)
turtle.down()
rawy = -rawy
canvas = turtle.getcanvas()
canvas.pack(fill="both", expand=True)
ids = canvas.find_overlapping(rawx, rawy, rawx, rawy)
if ids: # if list is not empty
index = ids[0]
color = canvas.itemcget(index, "fill")
if color != '':
print(color.lower())
def getcoordinates():
turtle.onscreenclick(turtle.goto)
turtle.onscreenclick(modifyglobalvariables) # Here's the change!
turtle.onscreenclick(textbox_click)
def modifyglobalvariables(rawx,rawy):
global xclick
global yclick
xclick = int(rawx//1)
yclick = int(rawy//1)
print(xclick)
print(yclick)
def main():
border(150,"purple")
turtle.begin_fill()
turtle.down()
turtle.color("purple")
turtle.up()
# Creates the big shape
x1=150
y1=3
turtle.setposition(x1,y1)
big_shape(5,2,50)
turtle.begin_fill()
turtle.down()
turtle.up()
# Circle
x1=70
y1=-107
turtle.setposition(x1,y1)
turtle.begin_fill()
turtle.circle(50)
turtle.color("orange")
turtle.end_fill()
getcoordinates()
turtle.done()
main()
을'모든 요소를 겹쳐 유지 ids'. 어쩌면 보라색 사각형이 최상위 요소 일 것입니다. 'ids'에서 다른 값들을 확인할 수 있습니다. – furas