1from colormap import rgb2hex
2from colormap import hex2rgb
3
4print(rgb2hex(255, 255, 255))
5print(hex2rgb('#FFFFFF'))
6
7>>> #FFFFFF
8>>> (255, 255, 255)
1def hex2rgb(color):
2 hex = color.lstrip('#')
3 rgb = tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))
4
5 return rgb
6
7hex_color = "#B4FBB8"
8rgb_color = hex2rgb(hex_color)
9
10print(rgb_color)
11#(180, 251, 184)
1# Convert RGB to HEX
2rgb = (255,255,255) # ---------> pure white
3print("#%02x%02x%02x" % rgb) # -----> #ffffff
4
5# - sabz
1h = input('Enter hex: ').lstrip('#')
2print('RGB =', tuple(int(h[i:i+2], 16) for i in (0, 2, 4)))
1import matplotlib
2
3print(matplotlib.colors.to_hex([ 0.47, 0.0, 1.0 ]))
4print(matplotlib.colors.to_hex([ 0.7, 0.321, 0.3, 0.5 ], keep_alpha=True))
5
6print(matplotlib.colors.to_rgb("#aabbcc"))
7print(matplotlib.colors.to_rgb("#ddee9f"))