Version 3 of Simple Entry Demo

Updated 2006-02-02 17:12:22

HJG Simple demo of Tk: label, entry, button and a picture. Layout with frames and pack. No error-checks on input (empty, non-numeric) or overflow of result.


 #!/bin/sh
 # Restart with tcl: -*- mode: tcl; tab-width: 4; -*- \
 exec wish $0 ${1+"$@"}

 # EntryDemo02.tcl - HaJo Gurt - 2006-02-02 - http://wiki.tcl.tk/15398
 #: Tk-Demo: Enter 3 numbers, show sum and product

  package require Tk

  proc Calc {} {
  #: Calculate results  /  !! No error-checks !!
    global A B C  P S
    set S [ expr { $A + $B + $C } ]
    set P [ expr { $A * $B * $C } ]
  }

  frame  .f1     ;# Frame for Input-fields + button
  frame  .f2     ;# Frame for Output

  label  .labA -text "A:"
  label  .labB -text "B:"
  label  .labC -text "C:"
  label  .labS -text "S="
  label  .labP -text "P="

  entry  .entA -textvar A -width 11
  entry  .entB -textvar B -width 11
  entry  .entC -textvar C -width 11
  entry  .entS -textvar S -state readonly
  entry  .entP -textvar P -state readonly

  button .ok -text "OK" -command Calc

  pack   .f1 .f2

  pack   .labA .entA  -in .f1  -side left 
  pack   .labB .entB  -in .f1  -side left
  pack   .labC .entC  -in .f1  -side left

  pack   .ok          -in .f1  -side left -padx 10

  pack   .labS .entS  -in .f2  -side left
  pack   .labP .entP  -in .f2  -side left

 #package require Img                      ;# Images other than .gif
  image create photo Pic1 -file "tcl.gif"
  label .labPic1 -image Pic1  
  pack  .labPic1 -padx 4 -pady 4

  set A 2147483647
  set B 0
  set C 1
  Calc

  bind . <Return>  Calc

  wm title . "EntryDemo2"
  focus -force .entA

Is there a simple/portable way to check for overflow ?


Category GUI