[英]Extract certain value in column treeview
我已经尝试了很多东西,但无法让它发挥作用。 基本上我在这个块中试图做的是创建一个按钮,它将创建我的 treeview 的 pdf。 我想要做的就是对我的 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)
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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.