This is a small 4-function-calculator. It uses [expr] directly to calculate the results, so you may need to append ".0" to numbers to do calculations in floating point. E.g. "3/2" will be done on integers: "3/2=1", so you might want to do "3/2.0" instead. Also, you cannot use the result of a calculation for further calculations, i.e. if you have "17/4.0=4.25" in the display and you continue to type "*3=" you get an error. ---- ====== # Small calculator package require Tk button .quit -text "Off" -fg red -command exit label .readout -textvariable result -bg white set result " " button .key0 -text "0" -width 3 -command {append result 0} button .key1 -text "1" -width 3 -command {append result 1} button .key2 -text "2" -width 3 -command {append result 2} button .key3 -text "3" -width 3 -command {append result 3} button .key4 -text "4" -width 3 -command {append result 4} button .key5 -text "5" -width 3 -command {append result 5} button .key6 -text "6" -width 3 -command {append result 6} button .key7 -text "7" -width 3 -command {append result 7} button .key8 -text "8" -width 3 -command {append result 8} button .key9 -text "9" -width 3 -command {append result 9} button .point -text "." -width 3 -command {append result .} button .plus -text "+" -width 3 -command {append result +} button .minus -text "-" -width 3 -command {append result -} button .times -text "*" -width 3 -command {append result *} button .div -text "/" -width 3 -command {append result /} button .equal -text "=" -width 3 -command {append result = [expr $result]} button .sign -text "+/-" -width 3 -command {set result [expr $result*-1]} button .clear -text "C/CE" -width 3 -command {set result ""} grid .quit .readout -sticky nsew grid .key7 .key8 .key9 .times .clear -sticky nsew grid .key4 .key5 .key6 .minus .div -sticky nsew grid .key1 .key2 .key3 .plus .equal -sticky nsew grid .key0 .sign .point -sticky nsew #More than 4 columns: #grid configure .sbar -columnspan 4 -padx 4 grid configure .readout -columnspan 4 -padx 4 grid configure .plus -rowspan 2 grid configure .equal -rowspan 2 #bind . <1> {append result 1} #bind . <2> {append result 2} #bind . <3> {append result 3} bind . <4> {append result 4} bind . {append result 5} focus -force . ====== ---- See also: [A little calculator] - [A fancier little calculator] [HJG] Changed "aufgabe" --> "result". <> Application | GUI | Office Automation