[Python] how to adjust tkinter treeview rowheight, the content is wrapped when over one row

Discussão em 'Python' iniciado por Stack, Maio 9, 2025.

  1. Stack

    Stack Membro Participativo

    This is the problem screenshot:

    [​IMG]

    And this is my code:

    tree_frame = Frame(self.root)
    tree_frame.pack()
    self.tree = ttk.Treeview(tree_frame, columns=['1', '2', '3'], show='headings', height=10)
    self.tree.grid(row=0, column=0, columnspan=4, sticky=NSEW)
    scrollbar_x = Scrollbar(tree_frame, orient=HORIZONTAL, command=self.tree.xview)
    scrollbar_x.grid(row=1, column=0, columnspan=4, sticky=EW)
    scrollbar_y = Scrollbar(tree_frame, orient=VERTICAL, command=self.tree.yview)
    scrollbar_y.grid(row=0, column=4, sticky=NS)
    self.tree.configure(xscrollcommand=scrollbar_x.set, yscrollcommand=scrollbar_y.set)
    self.tree.column('1', width=220, anchor='center')
    self.tree.column('2', width=220, anchor='center')
    self.tree.column('3', width=180, anchor='center')


    I tried change the height ttk.Treeview(tree_frame, columns=['1', '2', '3'], show='headings', height=20), but it didn't make the row but the whole tree higher. I guess the problem may caused by different dpi, but I'm not so sure can anyone help me solve this problem.

    Continue reading...

Compartilhe esta Página