[Tkinter-discuss] Get height of a row in Treeview in Tkinter with Python3

c.buhtz at posteo.jp c.buhtz at posteo.jp
Tue Feb 13 16:00:48 EST 2018


X-Post: https://stackoverflow.com/q/48736168/4865723

I want to know how height (in pixel) is a row in a tkinter.Treeview.

I know how I can manipulate the height (see example below) with the
styling mechanism. But I want to read it first - because it depends on
the operating system, fonts, etc. And I couldn't find something in the
style object I could read for this.

My goal is to modify the rowheight with a relative factor. e.g. 1,5 of
the original height.

#!/usr/bin/env python3

from tkinter import *
from tkinter import ttk

if __name__ == '__main__':
    root = Tk()
    style = ttk.Style()

    # here I set the `rowheight`
    style.configure('MyTreeView.Treeview', rowheight=45)

    tree = ttk.Treeview(root, style='MyTreeView.Treeview')
    tree.pack()

    for i in range(5):
        tree.insert(parent='',
                   index=END,
                   text='item {}'.format(i))

    root.mainloop()


More information about the Tkinter-discuss mailing list