Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to generate RGBcolor in RGBColor(0x42, 0x24, 0xE9) format

I am working with python docx and here I am stuck.

from docx import Document
document = Document()
run = document.add_paragraph().add_run()
font = run.font
from docx.shared import RGBColor
font.color.rgb = RGBColor(0x42, 0x24, 0xE9)

This generate RGB(66, 36, 233) when viewed from microsoft word.

how can I get RGBColor(0x42, 0x24, 0xE9) type color given RGB(66, 36, 233) format ?

like image 600
Rahul Avatar asked Nov 10 '16 05:11

Rahul


1 Answers

The three parameters to RGBColor are just integers, so:

RGBColor(66, 36, 233)

Produces the same results as:

RGBColor(0x42, 0x24, 0xE9)

The 0x prefix is just a way of telling Python that what follows is to be interpreted as a base-16 number. It doesn't have to do with python-docx per se; any way you get an integer between 0 and 255 into those three positions will work fine.

like image 119
scanny Avatar answered Oct 27 '22 08:10

scanny