I have tried alot of things but cannot get it to work. Basically what im trying to do in this block is create a button that will create a pdf of my treeview. All i want to do is for each row in my treeview that has data is to extract data only from one of the columns "line" and put into a pdf. is it because the line
pdf.cell(200, 10, txt=word, ln=1, align='L')
has txt
which does not work with the string variable word? Help is appreciated!
def create_pdf():
# save FPDF() class into a variable pdf
pdf = FPDF()
# Add a page
pdf.add_page()
word = StringVar()
for line in tree.get_children():
pdf.set_font("Arial", size=10)
# for value in tree.item(line)['values']:
# word = [set(value)]
word.set((line, 'Line'))
pdf.cell(200, 10, txt=word, ln=1, align='L')
pdf.output("GFG.pdf")
return None
createpdf = Button(frame5, text="Create PDF", relief=GROOVE, command=create_pdf, width=10)
createpdf.place(x=1668, y=10, height=30)
CodePudding user response:
word
is a StringVar
, so txt=word
is not working.
Actually you don't need to use StringVar
at all. Also you need to use tree.set(line, 'Line')
to get the value of the column Line
of row line
:
def create_pdf():
# save FPDF() class into a variable pdf
pdf = FPDF()
# Add a page
pdf.add_page()
pdf.set_font("Arial", size=10)
for line in tree.get_children():
# get the value of the cell in column 'Line'
word = tree.set(line, 'Line')
pdf.cell(200, 10, txt=word, ln=1, align='L')
pdf.output("GFG.pdf")