【发布时间】:2018-05-03 01:41:50
【问题描述】:
我在 Python 中使用 Turtle Graphics 来完成一个更大的程序。我可以使用turtle.onscreenclick返回用户点击的点
但是,我想提取用户点击点的 RGB 颜色。这甚至可以在海龟图形中完成,如何实现?谢谢!
import turtle
# Global variables specifying the point clicked
xclick = 0
yclick = 0
# Draw a rectangle that is red
height = float(50)
length = height *(1.9)
length = round(length,2)
turtle.begin_fill()
turtle.color("red")
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()
# Gets the click
def getcoordinates():
turtle.onscreenclick(turtle.goto)
turtle.onscreenclick(modifyglobalvariables)
# Modifies the global variables
def modifyglobalvariables(rawx,rawy):
global xclick
global yclick
xclick = int(rawx//1)
yclick = int(rawy//1)
print(xclick)
print(yclick)
getcoordinates()
turtle.done()
【问题讨论】: