Tcl Tk - gregorymorrison/euler1 GitHub Wiki

Tk is a platform-independent GUI library introduced in the mid '90s, originally for Tcl although bindings for it have been written for many other languages. Here I've extended my version of Euler1 in Tcl, adding the simplest possible Tk GUI - a button that displays the solution. When you click the button, the program exits:

#!/usr/bin/wish
# Euler1 in Tcl/Tk

proc euler1 {n} {
    set sum 0; set i 0 

    while {$i < $n} {
        if {$i%3==0 || $i%5==0} {
            set sum [expr $sum+$i]
        }
        incr i
    }

    return $sum
}

button .btnEuler -text [euler1 1000] -command { exit }
pack .btnEuler

To run, simply call your script:

$ euler1.tk

And here is the result: