如果我要创建一个圆,并单击按钮来迭代颜色,如下面的代码所示:
color_iteration1 = itertools.cycle(('blue', 'green', 'orange', 'red', 'yellow'))
color_iteration2 = itertools.cycle(('blue', 'green', 'orange', 'red', 'yellow'))
color_iteration3 = itertools.cycle(('blue', 'green', 'orange', 'red', 'yellow'))
color_iteration4 = itertools.cycle(('blue', 'green', 'orange', 'red', 'yellow'))
def callback1():
mcircle1 = mycanvas.create_oval(10,620,86,675, outline='#000000',fill=next(color_iteration1))
def callback2():
mcircle2 = mycanvas.create_oval(100,620,176,675, outline='#000000',fill = next(color_iteration2))
def callback3():
mcircle3 = mycanvas.create_oval(190,620,266,675, outline='#000000',fill = next(color_iteration3))
def callback4():
mcircle4 = mycanvas.create_oval(280,620,356,675, outline='#000000',fill = next(color_iteration4))
B1 = Button(root,text='B1',command =callback1)
B2 = Button(root,text='B2',command =callback2)
B3 = Button(root,text='B3',command =callback3)
B4 = Button(root,text='B4',command =callback4)
在任何给定的时间,我将如何存储圆圈中包含的所有颜色,该颜色包含在迭代列表中。例如,如果我按下按钮两次并落在绿色上,我怎么能说mcircle现在是绿色并将其存储为变量?
哦,如果还更容易,是否有一种方法可以遍历圆的每个像素,并且如果它检测到某个RGB值,它会发出一个标志以将某个变量变成等于RGB值在颜色范围内的任何颜色。圆圈?
如果保留该项目的引用(的返回值create_oval
),则可以使用Canvas.itemcget
以下方法获取该项目的选项:
oval = canvas.create_oval(10, 10, 20, 20, fill='red')
canvas.itemcget(oval, 'fill') # => Returns 'red'
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句