package require Tk namespace eval guess { variable max 100 variable min 1 variable count -1 variable guess 0 namespace export * } proc guess::gui {} { pack [label .g] pack [frame .c] -pady 5 pack [button .c.l -text "Lower" -command guess::lower] -side left -padx 3 pack [button .c.h -text "Higher" -command guess::higher] -side left -padx 3 pack [button .c.ok -text "Done" -command guess::done] -side left -padx 3 guess::next } proc guess::next {} { variable min variable max variable guess variable count incr count set guess [expr {($max+$min)/2}] .g conf -text "The number is: $guess ?" } proc guess::higher {} { variable guess variable min $guess guess::next } proc guess::lower {} { variable guess variable max $guess guess::next } proc guess::done {} { variable count .g conf -text "Guessed it in $count tries." .c.ok conf -text Exit -command exit } guess::gui