Version 10 of Invoice-Demo

Updated 2015-05-20 18:55:13 by MiHa

if 0 {


Introduction

MiHa 2015-05-13: This is a demo for a tcl/tk-program with all the essential GUI-elements.
It acts as a simple invoice-program with menu, entry-form and output (planned: one printed page).

All the data is just strings of text, no validation, no calculation.

With ideas and code from the following pages:

}


Program 1

 # InvoiceDemo04.tcl - Mike Hase - 2015-05-19
 # http://wiki.tcl.tk/29284
 # Simple "invoice"-themed GUI-program: menu, form for data-entry, output to screen and printer.
 # (Menu and output not done yet)

 global data maxFNr

 set FieldNames1 {Date Title Name Street City Phone}
#set FieldNames2 {art1Nr art1qty art1name art1price price1}
 set FieldNames2 {Article-Number Quantity Description Price Total}

 set fNr   0
 set artNr 0

 # Frame for customer-data:
 frame .f1
 foreach field $FieldNames1 {
        incr fNr
       #set data($fNr) $fNr        ;##
        set lb [label .f1.lb$field -text $field]
        set en [entry .f1.en$field -justify left -textvar data($fNr) ]
        grid $lb $en -padx 4 -pady 2
        grid $lb -sticky e
        grid $en -sticky ew
 }

 # Frame for article-data:
 frame .f2
 incr artNr                                ;# Todo: extend to more articles
 foreach field $FieldNames2 {
        incr fNr
       #set data($fNr) $fNr        ;##
        set lb [label .f1.lb$field -text $field]
        set en [entry .f1.en$field -justify right -textvar data($fNr) ]
        grid $lb $en -padx 4 -pady 2
        grid $lb -sticky e
        grid $en -sticky ew
 }
 set maxFNr $fNr

 # Frame for buttons:
 frame .f8
 button .f8.b1 -text New     -command { data0 }
 button .f8.b2 -text Test1   -command { data1 }
 button .f8.b3 -text Test2   -command { data2 }
 button .f8.b4 -text Show    -command { showData  }
 button .f8.b5 -text Print   -command { printData }

 button .f8.b6 -text Exit    -command { exit }

 grid .f8.b1  .f8.b2  .f8.b3  .f8.b4  .f8.b5  .f8.b6
 pack .f1 .f2 .f8 -side top


 proc data0 {} {
 # Clear data in entry-fields
   for {set f 1} {$f <= $::maxFNr} {incr f} {
      set ::data($f) ""
    ##set ::data($f) $::maxFNr
    ##update        ;##
   }
 }

 proc data1 {} {
 # Fill entry-fields with testdata
   set ::data(1) "2015-05-13"
   set ::data(2) "Mr."
   set ::data(3) "Smith"
   set ::data(4) "Mainstreet 123"
   set ::data(5) "Newtown"
   set ::data(6) "555-6789"
   set ::data(7) "0815"
   set ::data(8) "2"
   set ::data(9) "T-Shirt"
   set ::data(10) " 9.99"
   set ::data(11) "19.98"
 }

 proc data2 {} {
 # Fill entry-fields with testdata
   set fNr   0
   set values {
      "2015-05-14"
      "Mrs." "Miller" "Highstreet 99" "Oldsville" "555-9876"
      "0816" "1" "T-Shirt XL" "12.24" "12.24"
   }
   foreach v $values {
        incr fNr
        set ::data($fNr) $v
   }
 }

 # Todo:
 proc showData  {} { bell }
 proc printData {} { bell }

 ### EOF ###

Output

Invoice-Demo:
...

Remarks

MiHa: This is a nice small demo of a simple program using only basic, essential GUI-features:

  • Menu
  • Buttons (to see them, uncomment that "if 0"-section)
  • Hotkeys
  • Labels
  • Entry-fields
  • Messagebox
  • Title at top of window
  • Icon at top of window (currently, this needs an external file)
  • frames, pack and grid

There is lots of more advanced GUI-stuff not covered so far, e.g.:

  • Checkboxes
  • Radiobuttons
  • Fancy textformating, fonts (i.e. for a nice help-window)
  • Listview
  • Scrollbars
  • separate dialog-windows (i.e. for the data-entry form)

But if any of that gets included, and the program gets more complex,
it might be better to put that into a separate program.

The data is just simple strings of text, all of the same length, no validation, no calculation, no special logic, etc.
This definitely needs work for any real-world application.

Also, there is no file-I/O for data or configuration.

I haven't looked into the printing stuff yet, so if anybody feels competent, you are welcome to fill in that part.


See also: