set ini 1
set fin 300
set paso 1
set fon "arial 10"
catch {destroy .t}
toplevel .t -bg "#AAF"
wm geometry .t "200x300+0+0"
wm withdraw .
wm title .t "Sumatoria de numeros contiguos y/o separados"
grid [label .t.l0 -text "Numero inicial" -font $fon] -sticky ew
grid [entry .t.e0 -textvar ini -font $fon -width 3] -sticky ew
grid [label .t.l1 -text "NUmero final" -font $fon] -sticky ew
grid [entry .t.e1 -textvar fin -font $fon -width 3] -sticky ew
grid [label .t.l2 -text "Separacion" -font $fon] -sticky ew
grid [entry .t.e2 -textvar paso -font $fon -width 3] -sticky ew
grid [button .t.b0 -text "sumar" -font $fon -command {sumar $ini $fin $paso}] -sticky ew
grid [button .t.b1 -text "Reset" -command {foreach {ini fin paso suma} "1 100 1 0" {break}}] -sticky ne
grid [button .t.b2 -text "Salir" -command {tk_messageBox -message "BYE";exit} ] -sticky ns
proc sumar {ini fin paso} {
set sum 0
for {set i $ini} {$i <= $fin} {incr i $paso} {
set sum [expr $sum+$i]
}
tk_messageBox -message "la suma desde $ini hasta $fin con saltos de $paso es: $sum"
wm withdraw .
}