gtk3+ and python rgba convert to hex

前端 未结 1 825
故里飘歌
故里飘歌 2021-01-28 01:17

i using gtk3 i found that it use rgba for representing color, but the (red,green,blue,alpha) are not integer between 0-255 but floating point n

相关标签:
1条回答
  • 2021-01-28 01:40

    Assuming the problem is that the number should have leading zeros when they are only 1 digit. Here is a solution for that.

    def convert_to_hex(rgba_color) :
        red = int(rgba_color.red*255)
        green = int(rgba_color.green*255)
        blue = int(rgba_color.blue*255)
        return '0x{r:02x}{g:02x}{b:02x}'.format(r=red,g=green,b=blue)
    
    0 讨论(0)
提交回复
热议问题