Version 7 of vertical labels

Updated 2004-01-23 19:24:41

MGS - Here's a nasty-ish hack to make labels with vertical text. Not rotated text, just with the letters stacked on top of each other. For spaces, you need to insert two newlines.

   label .l -text "Vertical\n\nLabel" -wraplength 1
   pack  .l

Make sure the label is packed/gridded so as not to expand or fill horizontally.


RS Another way is:

 label .l2 -text [join [split "Vertical text" ""] \n]

This way is slower and alters the actual text contained in the label rather than just how it wraps, though. -FW - RS: Well, it processes a copy of the text, which is perfectly normal in Tcl - but needs no workaround for spaces... ;-)


Mike Tuxford thinks both of those are clever and would come in handy for use with Animated Vertical Tabs


ulis, 2003-01-23. Torsten in c.l.t. asked for a vertical label package. Here it is.

http://perso.wanadoo.fr/maurice.ulis/tcl/vlabel.png

Vlabel package

  if {![info exists ::vlabel::version]} \
  {
    namespace eval ::vlabel \
    {
      namespace export vlabel
      package require Tk
      variable version 0.1
      package provide Vlabel $version
      proc vlabel {w args} \
      {
        label $w
        rename $w ::vlabel::_$w
        interp alias {} ::$w {} ::vlabel::vconfig $w
        if {$args != ""} { eval vconfig $w $args }
        return $w
      }
      proc vtext {text} { join [split $text {}] \n }
      proc vconfig {w args} \
      {
        set l [llength $args]
        if {$l == 0} { return [eval ::vlabel::_$w config $args] }
        set n 0
        foreach {key value} $args \
        {
          incr n
          if {$n == $l} { return [::vlabel::_$w config $key] }
          switch -glob -- $key \
          {
            -text   \
            { ::vlabel::_$w config -text [vtext $value] }
            default \
            { ::vlabel::_$w config $key $value }
          }
        }
      }
    }
  }

Demo

  package require Vlabel
  namespace import ::vlabel::vlabel
  pack [vlabel .l -text vlabel -bg gold]

Category GUI

Category Widget