首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >提取列treeview中的某些值

提取列treeview中的某些值
EN

Stack Overflow用户
提问于 2021-12-15 20:14:42
回答 1查看 130关注 0票数 1

我已经尝试了很多事情,但无法使它发挥作用。基本上,我试图在这个块中创建一个按钮,该按钮将创建一个pdf的我的treeview。我所要做的就是对我的treeview中的每一行都有数据,只从其中一列“行”中提取数据,然后放入pdf中。是因为行pdf.cell(200, 10, txt=word, ln=1, align='L')txt,它不能处理字符串变量word吗?我们很感激你的帮助!

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-16 00:57:51

word是一个StringVar,所以txt=word不能工作。

实际上,您根本不需要使用StringVar。此外,还需要使用tree.set(line, 'Line')来获取行line的列Line的值。

代码语言:javascript
复制
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")
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70369795

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档