question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to resize rowheight in Treeview

See original GitHub issue

Hi,

When using ttkbootstrap, I’m unable to resize the rowheight in a Treeview. If I increase the font size, the rows just get cut off and I’ve been unable to get anything to work for resizing them. Any fix or work around for this? Thanks in advance!

See example:

from tkinter import *
from tkinter import ttk
from ttkbootstrap import Style

root = Tk()
root.geometry('600x600')

style = Style(theme='journal')

style.configure("Treeview.Heading", font=(None, 20), rowheight=40)
style.configure("Treeview", font=(None, 20), rowheight=40)

tv_apps = ttk.Treeview(
    root,
    columns=('Application', 'Status'),
    show='headings')

tv_apps.place(
    x = 50, y = 50,
    width = 450, height = 350)

tv_apps.heading('#1', text='Application')
tv_apps.column('#1', anchor='w')

tv_apps.heading('#2', text='Status')
tv_apps.column('#2', anchor='w')


tv_apps.insert('', 'end', values=('App1', 'Waiting'))
tv_apps.insert('', 'end', values=('App2', 'Working...'))        

if __name__ == '__main__':
    root.mainloop()

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
israel-dryercommented, Dec 25, 2021

The root cause of this is that styles are created on-demand in ttkbootstrap 1.0+. When a style is used, it is registered with the Style object so that the style object knows not to attempt to create it again. Thus, until a style is actually used, it either does not exist, or ttkbootstrap does not know about it (in this case) and thus overwrites it with it’s own default settings. This is why the code “works” when moving the style configure after creating and using the default treeview style.

This also causes another side effect that I wish to fix, in that you cannot subclass a ttk class that does not exist yet, which is every style in ttkbootstrap until it is used in a widget.

The fix is override the Style.configure method so that it first checks for a ttkbootstrap style, and creates it if not already existing (this would include default styles such as “Treeview”). Then, the user’s customizations will be applied to either the existing style or a subclassed version of it. The resulting behavior of Style.configure would then match the user’s expectations while still maintaining the goal of not creating unused styles.

1reaction
vectar7commented, Dec 25, 2021

Oh very nice. Thanks for the advice and the workaround! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - ttk.Treeview - Can't change row height - Stack Overflow
How can I change the height of the rows in the treeview as in prevoius attempts font size can be increased but the...
Read more >
How can I set the row height in Tkinter TreeView?
To set the row height of the Treeview widget, you can create an instance of ttk themed widget where you can specify the...
Read more >
Meme Overflow on Twitter: "ttk.Treeview - Twitter
Meme Overflow on Twitter: "ttk. Treeview - Can't change row height https://t.co/3UB5UJhpy9 #python27 #tkinter #python #ttk #python3x https://t. ...
Read more >
45. ttk.Treeview
The Treeview widget generalizes this concept so that you can use it to display any hierarchical structure, and the reader can collapse or...
Read more >
GridView - How to catch the moment when a row height is ...
I am trying to figure out how I hook into a GridView resize row event (or row size changed event). My GridView has...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found