Reputation: 16958
I wrote a small app recently that needs to be cross-platform. I used Python and Tkinter for the GUI.
It works great but recently I got a new laptop with a hiDPI screen and it seems to mess up the TreeView (see image below). The text height is too big compared to the height of the rows.
The picture is taken from a virtual machine running Windows 7 as a guest. I had to set the text to a larger size (125%) to be able to read on the screen (every other program I've tried work fine with this setting).
Is there any way to set the height of a row in Tkinter TreeView? I haven't seen anything like that in the docs.
Upvotes: 7
Views: 20635
Reputation: 1939
I already have a variable setup for font size and would like to avoid setting up a variable for row height. So my code looks like this:
style = ttk.Style()
style.configure("Treeview.Heading", font=(None, LARGE_FONT), \
rowheight=int(LARGE_FONT*2.5))
style.configure("Treeview", font=(None, MON_FONTSIZE), \
rowheight=int(MON_FONTSIZE*2.5))
When LARGE_FONT
is set to 14
, the row height is set to 35
. When MON_FONTSIZE
is set to 12
, the row height is calculated as 30
.
The end result has the correct spacing (IMO) for the system font. YMMV for other font families though:
Upvotes: 7
Reputation: 13729
s = ttk.Style()
s.configure('Treeview', rowheight=40) # repace 40 with whatever you need
Upvotes: 14