'how to add (.PNG) image in (.docx) created file

from pathlib import Path
from docxtpl import DocxTemplate
import datetime
import PySimpleGUI as sg

document_path = Path(__file__).parent / "Simple_file_location.docx" 

# add your template here

doc = DocxTemplate(document_path)
today = datetime.datetime.today()
layout = [[sg.Text("Assembly"), sg.Input(key="ASSEMBLY")],
          [sg.Text("ArtikelNr"), sg.Input(key="ARTIKELNR")],
          [sg.Text("Customer"), sg.Input(key="CUSTOMER")],
          [sg.Text("Reference"), sg.Input(key="REFERENCE")],
          [sg.Text("OrderNr"), sg.Input(key="ORDERNR")],
          [sg.Text("elspec serial no."), sg.Input(key="ELSPECSERIALNR")],
          [sg.Text("umgebungsTemp"), sg.Input(key="UMGEBUNGSTMP")],
          [sg.Text("validator name"), sg.Input(key="VALIDATORNAME")],
          [sg.Button("Vorlage erstellen"), sg.Exit()], ]

window = sg.Window("Druck Vorlage ", layout, element_justification="right")

while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED or event == "Exit":
        break

    if event == "Vorlage erstellen":
        values["TODAY"] = today.strftime("%d.%m-%Y")
        doc.render(values)
        doc.save(Path(__file__).parent / "generated_wordTemp.docx") 

window.close()

I am trying to add a png file in this word document. The .png file is stored in the same directory.



Sources

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

Source: Stack Overflow

Solution Source