我用python创建了一个turtle程序,它在位置(0,0)周围创建了一个色轮。这是一个纸篓:http://pastebin.com/xDyddfwa。我希望能够做的是,能够点击方向盘上的某个地方,然后被告知我点击的颜色围绕圆圈的度数。所以基本上,我想要的是圆坐标,而不是笛卡尔坐标。如果你运行色轮程序,它会提示你输入一个数字。如果输入6,它将绘制一个六色轮子。你会看到红色在底部的右边。我希望能点击它,得到0。如果我点击黄色,我会得到1,等等,我如何将这个值存储到一个变量中。(我在使用onclick()时遇到问题)请帮助。在
Tags:
onclick()
仅当您单击turtle时有效。每次单击时使用onscreenclick(callback)
执行函数。它给你(x,y)
,所以你必须计算angle
,然后把角度转换成正确的数字。它并不理想,因为它计算屏幕上每次点击的次数,而不仅仅是颜色。在编辑:}功能更强大-即,它具有绘制
^{pr2}$turtle
在后台使用tkinter
,而{arc
,pieslice
等功能,并且可以为画布上的每个对象分配鼠标单击。在在effbot.org网站:The Tkinter Canvas Widget
我觉得另一个基于OP代码的答案,在产生错误结果的同时,使问题变得更加复杂。下面是我尝试简化逻辑并生成正确的值(例如,6段HSB圆上的红色为0,黄色为1等)。我将圆旋转90度,以使数学对齐。此外,结果打印在圆的中心:
为了简化代码,我将颜色逻辑更改为0.0到1.0,并使其仅在单击色轮时才响应,而不仅仅是在窗口中的任何位置。在
相关问题 更多 >
编程相关推荐