我已经尝试了很多事情,但无法使它发挥作用。基本上,我试图在这个块中创建一个按钮,该按钮将创建一个pdf的我的treeview。我所要做的就是对我的treeview中的每一行都有数据,只从其中一列“行”中提取数据,然后放入pdf中。是因为行pdf.cell(200, 10, txt=word, ln=1, align='L')有txt,它不能处理字符串变量word吗?我们很感激你的帮助!
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)发布于 2021-12-16 00:57:51
word是一个StringVar,所以txt=word不能工作。
实际上,您根本不需要使用StringVar。此外,还需要使用tree.set(line, 'Line')来获取行line的列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")https://stackoverflow.com/questions/70369795
复制相似问题