我已經嘗試了很多東西,但無法讓它發揮作用。基本上,我在此塊中嘗試做的是創建一個按鈕,該按鈕將創建我的樹視圖的 pdf。我想要做的就是對我的樹視圖中包含資料的每一行僅從“行”列之一中提取資料并放入 pdf 中。是不是因為該行
pdf.cell(200, 10, txt=word, ln=1, align='L')
有txtwhich 不適用于字串變數 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)
uj5u.com熱心網友回復:
word是 a 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://www.uj5u.com/ruanti/383490.html
上一篇:在不同的列中顯示元素
下一篇:如何在tkinter中修改標簽?
