# Petite calculatrice très basique:

# zone de saisie de la commande:
entry .comand -textvariable comande -width 40 -state normal -bg white -justify center

set commande ""

# Affichage du résultat:
label .result -textvariable res -width 40

frame .fbt ;# frame pour les boutons

pack .comand .result .fbt -side top

set t 2
# Boutons:
button .fbt.enter -width $t -text "=" -command calculExpr
button .fbt.bpls  -width $t -text "+" -command {set comande "${comande}+" }
button .fbt.bmns -width $t -text "_" -command {set comande "${comande}-" }
button .fbt.bmult -width $t -text "*" -command {set comande "${comande}*" }
button .fbt.bdiv -width $t -text "/" -command {set comande "${comande}/" }
button .fbt.po -width $t -text "(" -command {set comande "${comande}(" }
button .fbt.pf -width $t -text ")" -command {set comande "${comande})" }
button .fbt.ce -width $t -text "CE" -command {set comande "" }

button .fbt.b1 -width $t -text "1" -command {set comande "${comande}1" }
button .fbt.b2 -width $t -text "2" -command {set comande "${comande}2" }
button .fbt.b3 -width $t -text "3" -command {set comande "${comande}3" }
button .fbt.b4 -width $t -text "4" -command {set comande "${comande}4" }
button .fbt.b5 -width $t -text "5" -command {set comande "${comande}5" }
button .fbt.b6 -width $t -text "6" -command {set comande "${comande}6" }
button .fbt.b7 -width $t -text "7" -command {set comande "${comande}7" }
button .fbt.b8 -width $t -text "8" -command {set comande "${comande}8" }
button .fbt.b9 -width $t -text "9" -command {set comande "${comande}7" }
button .fbt.b0 -width $t -text "0" -command {set comande "${comande}8" }
button .fbt.bvg -width $t -text "," -command {set comande "${comande}." }

grid .fbt.b7 .fbt.b8 .fbt.b9 .fbt.bpls .fbt.bmns -row 0 -padx 2
grid .fbt.b4 .fbt.b5 .fbt.b6 .fbt.bmult .fbt.bdiv  -row 1 -padx 2
grid .fbt.b1 .fbt.b2 .fbt.b3 .fbt.po .fbt.pf -row 2 -padx 2
grid .fbt.b0 .fbt.bvg .fbt.ce .fbt.enter -row 3  -padx 2

bind . <Escape> exit
bind . <Return> calculExpr
focus -force .comand

proc calculExpr {} {
  global comande res
  if { [ catch {set res [expr $comande]} fid ] } {
    set lg [string length $fid]
    set res "Synthax error"
    
    #  tk_messageBox -icon error -message "$fid " -title "ERREUR" -parent . -type ok
    

  }
    
}