Next / Previous / Contents / TCC Help System / NM Tech homepage

6.3. Color.__str__(): Convert to a string

Converting each 16-bit color component to its 8-bit equivalent is a simple matter of shifting out the low-order bits.

huey
# - - -   C o l o r . _ _ s t r _ _

    def __str__ ( self ):
        """Convert self to an X color name.
        """
        r8  =  self.r >> 8
        g8  =  self.g >> 8
        b8  =  self.b >> 8
        return "#%02X%02X%02X" % (r8, g8, b8)