A vertical line in a text widget

Arjen Markus (4 january 2008) Reading the wishlist for Tk 9.0, I stumbled on a request by NEM regarding a combination of the canvas and the text widgets. One idea was to have vertical lines in the text display.

Well, the script below demonstrates how you can do that (in principle at least):

# textw.tcl --
place [text .t] -x 0 -y 0
tkwait visibility .t
set height [winfo height .t]
set width  [winfo width  .t]
. configure -width $width -height $height
place [canvas .cv -width 0 -height $height -highlightthickness 0] -x [expr {$width/2}] -y 2
place [canvas .ch -width $width -height 0  -highlightthickness 0] -y [expr {$height/2}] -x 2 


  • If you use place in a frame, the frame needs to be resized via winfo explicitly (in the same way as the toplevel window in the code above)
  • I found out I need to resize the containing toplevel window myself
  • You need to compute the position of the canvases yourself in terms of columns or rows

But then: I only needed Tk 8.4 to do this.