ttk.Treeview – Adjust row height

We can change the height of rows in a treeview widget.

Take a look at the screenshot below:

img

The image of the house is big compared to the selected row.

We have 2 options to make it look better 1) make the image smaller by resizing it before inserting it into the treeview or 2) make the row’s height the same as the image’s height.

Let’s go with option number 2 – increase the row height. We’ll need to do that with ttk styles, which can alter the look of widgets.

# Define a unique style for all Treeview widgets
# in our program.
s = ttk.Style()
s.configure("Treeview", rowheight=125)

With the code above, we’re telling tkinter to use a rowheight of 125 pixels for each row in any Treeview widget that we create in our program.

Now when we select a row, it looks like this:

img