package require Tk

proc draw.x.axis.marks {w font color every} {
 array set metrics [font metrics $font]

 set y [expr {([winfo height $w] / 2) + $metrics(-ascent)}]
 set half_width [expr {[winfo width $w] / 2}]

 for {set x 0} {$x < [winfo width $w]} {incr x $every} {
  set mark [expr {$x - $half_width}]

  $w create text \
   $x $y -text $mark -font $font -fill white -tags axis
 } 
}

proc draw.y.axis.marks {w font color every} {
 
 set x [expr {[winfo width $w] / 2}]

 for {set y [winfo height $w]} {$y > 0} {incr y -$every} {
  set mark [expr {$y - ([winfo height $w] / 2)}]

  $w create text \
   [expr {$x + ([font measure $font $mark] / 2)}] $y \
    -text $mark -font $font -fill white -tags axis
 }
}

proc draw.x.axis {w font color} {
 set x1 0
 set x2 [winfo width $w]

 set y1 [expr {[winfo height $w] / 2}]
 set y2 $y1

 # This is our vertical line:
 $w create line $x1 $y1 $x2 $y2 -width 2 -fill $color -tags axis

 draw.x.axis.marks $w $font $color 30
}

proc draw.y.axis {w font color} {
 set x1 [expr {[winfo width $w] / 2}]
 set x2 $x1

 set y1 0
 set y2 [winfo height $w]

 # This is our horizontal line:
 $w create line $x1 $y1 $x2 $y2 -width 2 -fill $color -tags axis

 draw.y.axis.marks $w $font $color 30
}

proc draw.axis {w color} {

 # If we resize the window we need the axis to grow, so we delete the old.
 $w delete axis

 set font {Helvetica 10}

 draw.x.axis $w $font $color
 draw.y.axis $w $font $color
}

proc main {} {
 pack [canvas .c -width 400 -height 400 -bg gray20] -fill both -expand 1
 bind .c <Configure> {draw.axis %W green}
}
main