#!/usr/bin/wish
canvas .c -width 11c -height 11c
grid .c - - -sticky news
.c create rectangle 5m 5m 105m 105m
foreach i {1 2 3 4 5 6 7 8 9} {
  .c create line 5m $i.5c 105m $i.5c
  .c create line $i.5c 5m $i.5c 105m
}  

#foreach i { 1 2 3 4 5 6 7 8 9 10} {
#  .c create line 5m ${i}c 105m ${i}c
#  .c create line ${i}c 5m ${i}c 105m
#}  

set width 100
label .l -text "Измеренная ширина, мм" -anchor e
entry .e -width 5 -textvar width 
button .b -text "Вычислить" -command compute
grid .l .e .b 
grid configure .l -sticky news
grid configure .e -sticky nws
grid configure .b -sticky ns
bind .e <Key-Return> compute
set result [winfo fpixels . 1i]
label .lr -text "Разрешение, dpi"  -anchor e
label .r -textvar result -anchor w 
grid .lr .r - -sticky news
focus .e
.e icursor end
.e selection range 0 end
proc compute {} {
  global width result
  set result [expr {100.0/$width*[winfo fpixels . 1i]}]
}

