Discussion:
Another Tablelist question
Add Reply
Alan Grunwald
2024-11-15 19:20:14 UTC
Reply
Permalink
How do I tell the height occupied by a row (or a few rows) in a Tablelist?

tl;dr

I'm writing a GUI with a tablelist and a text widget displayed one above
the other in a paned window. I'd like to position the sash
programmatically so that the entire content of the tablelist is visible,
with the remaining space in the paned window occupied by the text widget.

I have observed that having the two widget heights in the ratio 1:3
works about right, but I'd like to get it spot on if I can.

All the rows in the tablelist are the same height, so if I knew that
height I could easily work out how much space is required for the five
or six rows that I've inserted. On the other hand, one might conceivably
have rows of different heights, so something to get the height of the
first few rows (or maybe even any set of adjacent rows) would be nice.

Thanks again (in advance)

Alan
greg
2024-11-16 00:00:44 UTC
Reply
Permalink
Post by Alan Grunwald
How do I tell the height occupied by a row (or a few rows) in a Tablelist?
tl;dr
I'm writing a GUI with a tablelist and a text widget displayed one above
the other in a paned window. I'd like to position the sash
programmatically so that the entire content of the tablelist is visible,
with the remaining space in the paned window occupied by the text widget.
I have observed that having the two widget heights in the ratio 1:3
works about right, but I'd like to get it spot on if I can.
All the rows in the tablelist are the same height, so if I knew that
height I could easily work out how much space is required for the five
or six rows that I've inserted. On the other hand, one might conceivably
have rows of different heights, so something to get the height of the
first few rows (or maybe even any set of adjacent rows) would be nice.
Thanks again (in advance)
Alan
Hello,

I find your question interesting.
My script does not correspond to your suggestion.
Perhaps bbox can help you.

Gregor

package require Tk
package require tablelist

# Main window
ttk::panedwindow .pw -orient vertical
pack .pw -fill both -expand true

# Tablelist
tablelist::tablelist .pw.tl -columns {0 "Name" left 0 "Value" center}
-height 5
.pw add .pw.tl -weight 0

# Text
text .pw.text -wrap word -background white
.pw add .pw.text -weight 1

# Tablelist insert datas
set data {
{"Item 1" "10"}
{"Item 2" "20"}
{"Item 3" "30"}
{"Item 4" "40"}
{"Item 5" "50"}
{"Item 6" "60"}
{"Item 7" "70"}
}
foreach row $data {
.pw.tl insert end $row
}

# https://www.nemethi.de/tablelist/tablelistWidget.html#bbox
wm geometry . 400x300
update idle
set hwin [winfo height .pw]
set hpw [.pw sash 0 $hwin]
set adjust [expr {$hwin - $hpw}]

update idle
#https://www.nemethi.de/tablelist/tablelistWidget.html#row_indices
#bottom instead of end, if the entire table is not visible
set bottomboxlist [.pw.tl bbox bottom]
set ybottombox [lindex $bottomboxlist 1]
set hbottombox [lindex $bottomboxlist 3]

set htl [.pw sash 0 [expr {$ybottombox + $hbottombox + $adjust }]]

puts "$hwin : $hpw : $adjust : $htl : $bottomboxlist : $ybottombox :
$hbottombox"
#300 : 295 : 5 : 169 : 2 145 110 19 : 145 : 19
Alan Grunwald
2024-11-16 00:23:32 UTC
Reply
Permalink
Post by greg
Post by Alan Grunwald
How do I tell the height occupied by a row (or a few rows) in a Tablelist?
tl;dr
I'm writing a GUI with a tablelist and a text widget displayed one
above the other in a paned window. I'd like to position the sash
programmatically so that the entire content of the tablelist is
visible, with the remaining space in the paned window occupied by the
text widget.
I have observed that having the two widget heights in the ratio 1:3
works about right, but I'd like to get it spot on if I can.
All the rows in the tablelist are the same height, so if I knew that
height I could easily work out how much space is required for the five
or six rows that I've inserted. On the other hand, one might
conceivably have rows of different heights, so something to get the
height of the first few rows (or maybe even any set of adjacent rows)
would be nice.
Thanks again (in advance)
Alan
Hello,
I find your question interesting.
My script does not correspond to your suggestion.
Perhaps bbox can help you.
Gregor
package require Tk
package require tablelist
# Main window
ttk::panedwindow .pw -orient vertical
pack .pw -fill both -expand true
# Tablelist
tablelist::tablelist .pw.tl -columns {0 "Name" left 0 "Value" center}
-height 5
.pw add .pw.tl -weight 0
# Text
text .pw.text -wrap word -background white
.pw add .pw.text -weight 1
# Tablelist insert datas
set data {
  {"Item 1" "10"}
  {"Item 2" "20"}
  {"Item 3" "30"}
  {"Item 4" "40"}
  {"Item 5" "50"}
  {"Item 6" "60"}
  {"Item 7" "70"}
}
foreach row $data {
  .pw.tl insert end $row
}
# https://www.nemethi.de/tablelist/tablelistWidget.html#bbox
wm geometry . 400x300
update idle
set hwin [winfo height .pw]
set hpw [.pw sash 0 $hwin]
set adjust [expr {$hwin - $hpw}]
update idle
#https://www.nemethi.de/tablelist/tablelistWidget.html#row_indices
#bottom instead of end, if the entire table is not visible
set bottomboxlist [.pw.tl bbox bottom]
set ybottombox [lindex $bottomboxlist 1]
set hbottombox [lindex $bottomboxlist 3]
set htl [.pw sash 0 [expr {$ybottombox + $hbottombox + $adjust }]]
$hbottombox"
#300 : 295 : 5 : 169 : 2 145 110 19 : 145 : 19
Thanks Gregor,

That should do the trick! Too late to try it now, I'll have a go in the
morning and follow-up here.

Alan

Loading...