proc compute {} {
  global function error

  .c delete function
  set error ""
  set x -5.0
  if {[catch {eval expr $function} out]} {
    set error $out
    return
  }
  set y $out
  set xlast [expr $x*20+100]
  set ylast [expr 100-$y*20]
  while {$x <= 5.0} {
    if {[catch {eval expr $function} out]} {
      set error $out
      return
    }
    set y $out
    set xnew [expr $x*20+100]
    set ynew [expr 100-$y*20]
    .c create line $xlast $ylast $xnew $ynew -tag function -fill green
    set xlast $xnew
    set ylast $ynew
    set x [expr $x+0.1]
  }
}


canvas .c -width 200 -height 200 -bg white
label .titel -text {Funktion($x) eingeben:}
entry .function -textvariable function
button .compute -text "Los" -command compute
message .error -textvariable error
grid .c -row 0 -column 0 -rowspan 4
grid .titel    -row 0 -column 1 -sticky ew
grid .function -row 1 -column 1 -sticky ew
grid .compute  -row 2 -column 1 -sticky ew
grid .error    -row 3 -column 1 -sticky ew
# Koordinatensystem
.c create line 0 100 200 100
.c create line 100 0 100 200
for {set i 20} {$i < 200} {incr i 20} {
  .c create line $i 97 $i 103
  .c create line 97 $i 103 $i
}
# Anfangswerte
set function {sin($x)}
set error ""
