Don't over think it. Pick a reasonable width based on the data. The user
can resize the window to make it bigger. Use what you consider the
minimum viewable size for -minwidth, which is where the scrollbar will
take over. How much leading space you should account for depends on how
much nesting you plan to do. Again, the user can resize the widget to
see more.
...
The immediate follow-up question that occurs to me is "What value
should I choose for the -minwidth option?", which leads on to a couple
of other questions:
o I can keep track of the various strings I want to display,
determine their sizes using [font measure] and ensure that
-minwidth and -width are set to their lengths, but what font
should I specify? I could configure the font on a per-tag basis >> and then find that font via [$tv tag configure {} -font] but that
returns an empty string in my case, where I haven't configured a
font. I guess it's TkDefaultFont - it would be nice not to have >> to guess but I can't find anything in the documentation.
o How much leading space do I need to allow? In my example above,
the strings are displayed on items that are down two levels. I >> can find how much each level is indented via
[ttk::configure [winfo style $tv] -indent]
but if I add double the indent to the length of the longest
string, and use the result to set -minwidth, it's not enough. I >> guess the extra space is required by the icon used to indicate >> that the some of the items have children, but I can't find what >> that image is.
Honestly? I think this stuff is hard and complicated enough that it
ought to be done by the widget itself, and the fact that it doesn't
should be regarded at least as a serious shortcoming, if not as a bug.
Alan
On 10/01/2026 21:22, Brian wrote:
Don't over think it. Pick a reasonable width based on the data. TheSage advice.
user can resize the window to make it bigger. Use what you consider
the minimum viewable size for -minwidth, which is where the scrollbar
will take over. How much leading space you should account for depends
on how much nesting you plan to do. Again, the user can resize the
widget to see more.
...
The immediate follow-up question that occurs to me is "What value
should I choose for the -minwidth option?", which leads on to a
couple of other questions:
o I can keep track of the various strings I want to display,
determine their sizes using [font measure] and ensure that
-minwidth and -width are set to their lengths, but what font >>> should I specify? I could configure the font on a per-tag basis
and then find that font via [$tv tag configure {} -font] but that
returns an empty string in my case, where I haven't configured a
font. I guess it's TkDefaultFont - it would be nice not to have
to guess but I can't find anything in the documentation.
o How much leading space do I need to allow? In my example above, >>> the strings are displayed on items that are down two levels. I >>> can find how much each level is indented via
[ttk::configure [winfo style $tv] -indent]
but if I add double the indent to the length of the longest >>> string, and use the result to set -minwidth, it's not enough. I
guess the extra space is required by the icon used to indicate >>> that the some of the items have children, but I can't find what
that image is.
Honestly? I think this stuff is hard and complicated enough that it
ought to be done by the widget itself, and the fact that it doesn't
should be regarded at least as a serious shortcoming, if not as a bug.
Alan
Sadly, I'm a good way down the track of trying to address this (and have already thought of an alternative way to fix things). This is important
to me because I have treeview widgets with associated scrollbars in
several places and I find that none of them scroll horizontally
correctly and sometimes the user can't resize the treeview. This is
probably because I'm not managing it correctly with grid/pack but I
can't face tracking that down at the moment.
In summary, this is a nice rat hole; I think I'll stay here for a while :-)
Alan
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,123 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 36:26:59 |
| Calls: | 14,371 |
| Files: | 186,380 |
| D/L today: |
2,465 files (701M bytes) |
| Messages: | 2,540,649 |