'Change font color of replaced text (Docx python)

I am currently exploring the world behind the docx module in python. So far so good. I have written a script with a tkinter interface that can quickly replace words in a template.

the only thing that I cant seem to figure out is the font color. I would like the words that are replaced to turn red so that when I look in the document I can see quickly which variables were changed and can check them.

I have seen a lot of post where they use ".add_run" etc. however I do not want to add text, simply make the replaced text red.

''''

variables = ["A", "B", "C"]
entryget  = ["word1", "word2", "word3"]

for i in doc.paragraphs:
    for a in range(len(variabelen)):
        if variabelen[a] in i.text:
             i.text  = i.text.replace(variabelen[a], entryget[a])

''''

and add something like: i.text.color.rgb = RGB(255, 0, 0)

thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source