I am making a calendar app using Tkinter in Python3 and I have a problem with the .txt to .pdf conversion.
My code saves user tasks to a .txt file and then can convert this .txt file to a pdf with the press of a button.
If the user creates a pdf with the tasks contained in the .txt file, then changes the .txt file and converts it to a pdf again, it will always convert the contents of the previous saved .txt file.
The only solution is to restart the whole program but I don't want that.
What can I change in my code so every time I change the .txt contents the pdf file contains the upgraded .txt file contents?
I will share the create pdf function below.
#function to create pdf
def PDFCreate():
pdf.set_font("Impact", size=15)
with open("FoundTasks.txt", "r", encoding = 'utf-8') as PDFTasks:
content = PDFTasks.read()
pdf.multi_cell(0, 10, txt=content, align='C')
# create or overwrite the tasks.pdf file with the contents of FoundTasks.txt
pdf.output("Tasks.pdf")
Instantiate the class FPDF inside the PDFCreate() function
I think you have only to instantiate the
pdfobject inside your functionPDFCreate()as you can see in the code below.File
pdf_create.py:How to test the previous function
To test your code (with my modification) I have used the following script (saved in the file
from_txt_to_pdf.pyin the same folder ofpdf_create.py).I have successfully test the previous code in my system:
IN your context instead of selecting
yyou will have to click to your button!!