1

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.

#!/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()
buhtz
  • 10,774
  • 18
  • 76
  • 149
  • It seems to be 20 but I couldn't fetch it from code yet – Nae Feb 14 '18 at 09:15
  • @Nae No this depends on the system, desktop environment, used themes, etc. – buhtz Feb 14 '18 at 14:42
  • Be that as it may but I think it's more of a Treeview default than being related to style. – Nae Feb 14 '18 at 15:22
  • @Nae You know or you think? First of all it depends on the selected font and its size. This is very different between plattforms and users especialy in such an plattform independend environment like Python3 with Tkinter. – buhtz Feb 14 '18 at 16:55
  • Well querying rowheight returns `""` for treeview. Also passing `""` as rowheight produces a default looking treeview. So I think treeview produces its default from elsewhere. – Nae Feb 14 '18 at 17:00
  • Can you explain how do you "querying"? OF coursee there is a "default" __depending__ on the __current system__. I want to know this default! Isn't that clear from my question? – buhtz Feb 14 '18 at 17:19
  • 1
    `style.lookup(tree['style'], 'rowheight')` returns `45` in the above code and `style.lookup(tree['style'], 'rowheight')` returns `''` if `tree`'s style hasn't been altered. Further `style.lookup('Treeview', 'rowheight')` returns `''`. Also, to me, it _is_ clear from the question. – Nae Feb 14 '18 at 17:24

0 Answers0