Posted some examples in another thread about colors in tkinter.
Just wanted to post a couple ways to get RGB colors in tkinter.
For python2.7
Just wanted to post a couple ways to get RGB colors in tkinter.
For python2.7
#! /usr/bin/env python2.7
from struct import pack
def rgb_color(rgb):
return('#' + pack('BBB', *rgb).encode('hex'))
print(rgb_color((255, 69, 123)))Output:#ff457bFor python3.+from base64 import b16encode
def rgb_color(rgb):
return(b'#' + b16encode(bytes(rgb)))
print(rgb_color((255, 69, 123)))Output:b'#FF457B'This works with all versions I testeddef rgb_color(rgb):
return '#%02x%02x%02x' % rgb
print(rgb_color((200, 100, 25)))Output:#c86419
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts
