On 1月22日, 上午1時56分, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Mon, 21 Jan 2008 08:15:02 -0800 (PST), "ÃCø¯" <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > > I was assigned dialog.colorDialog(self) return value to a result > > object, but I suspect that result.color is the attribute of the result > > object that can assign to a string variable. > > Showing the actual code would help... > > > There is a error prompt from python console "TypeError: list indices > > must be integers". > > Have any suggestion to solve this problem? > > Make sure you only have an integer when subscripting into a list? > > > When I print result.color, it is print out something like (255,0,0). > > Looks like a tuple -- probably > (red-level, green-level, blue-level) > where *-level is in the range 0..255 (x00..xFF); your example would be > (full red, no green, no blue) > > > How to covert result.color into a string? How to convert a string to > > result.color type? > > What type of string? > "0x%2.2X%2.2X%2.2X" % (r, g, b) > will produce a hex string of the form > 0xFF0000 > given your sample RGB > > If you want to get "Red", you'll need a look-up table and probably > some least-distance error function for items that don't directly match. > > (255, 0, 0) Red > (255, 255, 0) Yellow > (255, 0, 255) Magenta > (0, 255, 0) Green > (0, 255, 255) Cyan > (0, 0, 255) Blue > (0, 0, 0) Black > (255, 255, 255) White > > But where would you put: (127, 127, 63) [A half-black > Yellow > with 1/4 blue added].. Is it closer to Yellow, or to Black: 255-127 => > 128, but 127 - 0 => 127... Shorter simplistic distance means map this to > (0, 0, 0)... But (128, 128, 64) simplistic shorter distance would map to > Yellow > > -- > Wulfraed Dennis Lee Bieber KD6MOG > [EMAIL PROTECTED] [EMAIL PROTECTED] > HTTP://wlfraed.home.netcom.com/ > (Bestiaria Support Staff: [EMAIL PROTECTED]) > HTTP://www.bestiaria.com/
Many thanks, Dennis Lee Bieber for your fast reply! Regards, Andreas -- http://mail.python.org/mailman/listinfo/python-list