Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating button to entry interaction for Data-entry 1

Status
Not open for further replies.

FreddieBlassie

Programmer
Dec 11, 2001
20
US
I am starting out with TCL/TK and am trying to create a Data-entry GUI. I am using two books as resources, yet I don't see any examples of data entry that are based on button-clicks (rather than entry KeyPresses). All I want to do right now is to take the info in the entry box (or boxes) and send it to a procedure that will print the entry-contents via a "submit" button-click. Could someone please give me some advice or help? Thanks
 
Here is the code:
-----------------------
text .t
entry .e -textvariable ::value
button .b -text submit -command myProc

pack .t -pady 10
pack .e -pady 10
pack .b -pady 10

proc myProc {} { .t insert end $::value\n }

----------------------
Hitting the button adds the current entry value to the text window.
::value is a global variable retaining the value of the entry.


You can also use the validate command of the entry to send the value at focus out without the need of a button:
----------------------
text .t
entry .e -textvariable ::value -validate focusout -vcm { myProc; after idle {%W config -validate focusout}; return 1 }

pack .t -pady 10
pack .e -pady 10

proc myProc {} { .t insert end $::value\n }

---------------------
Here -validate indicates the event and -vcmd the action.
The "after idle" part is a trick to keep the entry doing what we want. The "return 1" is mandatory.

All is documented in the Tk manual entry for the entry widget.

ulis



 
Thanks Ulis! This is my first project for my internship job, so I really appreciate the help!
 
Would it be possible to send the output of multiple entry fields to multiple procedures via one button click? It looks as though you can only associate one command to one button. I thought maybe I could circumvent this through the configure subcommand after the first procedure processed, but apparently not.
 
Yes, only one command with one button.
Is this what you want?
-----------------------
text .t
entry .e1 -textvariable ::value1
entry .e2 -textvariable ::value2
entry .e3 -textvariable ::value3
button .b -text submit -command myProc

pack .t -pady 10
pack .e1 -pady 10
pack .e2 -pady 10
pack .e3 -pady 10
pack .b -pady 10

proc myProc {} { myProc1; myProc2; myProc3 }
proc myProc1 {} { .t insert end $::value1\n }
proc myProc2 {} { .t insert end $::value2\n }
proc myProc3 {} { .t insert end $::value3\n }
----------------------

myProc calls all 3 procs.

Eventually you can add some condition before calling each one.
Unfortunatly entry widgets do not have a modified flag.
But, if you need to be alerted at each modification, you can add a trace to each global variable like this:
-----------------------
trace add variable ::value1 w myProc1
proc myProc1 {name key op} { .t insert end "value1 modified\n" }
-----------------------

Each time the global variable ::value1 is modified (by the entry widget) Tcl will call myProc value1 "" w.

ulis
 
I see...so you just have to make procs1-3 subcommands of the original calling procedure. Thanks a lot for your help Ulis...being new to TCL and somewhat new to programming, it's taken a while for me to figure some of this stuff out. I think that should solve the problem though. I appreciate it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top