[Tkinter-discuss] How to use color in the canvas?

Fredrik Lundh fredrik at pythonware.com
Sun Mar 30 17:34:15 CEST 2008


chenguang Zhang wrote:

> Question 1.How to use the canvas.item_configure() method, for example, 
> if I want to change a line's color from red to blue, how to arrange the 
> parameters?

Use the fill or outline option, just as you do when creating new items.

> Question 2.Tkinter has a tkColorChooser and its return value is 
> something like ((0, 255, 255), '#00ffff'), and I'm wondering how to use 
> it. Normally the color used in function (like 
> mycanvas.create_line(ax,ay,bx,by,fill=color)) is in words such as 'red' 
> or 'gray', how could I make the program recognize the numbers?

the "#rrggbb" form can be used everywhere Tkinter expects a colour name:

http://effbot.org/tkinterbook/tkinter-widget-styling.htm#rgb-syntax

so you can just pass in the second part of the chooser's return value.

> Question 3. Suppose there are several separate lines in my canvas, all 
> are created in one single function like 'createThings()'. What should I 
> do so that when I choose a color from the tkColorChoose, all of them 
> change their colors, like all change from red to ((0, 255, 255), 
> '#00ffff')?

use tags:

     http://effbot.org/tkinterbook/canvas.htm#item-specifiers

</F>



More information about the Tkinter-discuss mailing list