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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issue in invoking TK procedure from TCL script

Status
Not open for further replies.

mkanna

Programmer
Jun 16, 2009
6
US
Hi,

I have written a small TCL script that will call TK procedure which will open a widgets and has text field init.
When I execute the TK procedure seperately through command line, it works fine. But when I call the TK procedure from TCL script, i dont see tk window coming up.

Not sure whether I missed anything.

Here is my TCL script,

************

#!/usr/bin/wish

package require Tcl
package require Tk
package require Tclx
package require Expect

set env(dev_dir) "/opt"

source [file join $env(dev_dir) local lib controllerAp.lib]
source [file join $env(dev_dir) local lib contr_cli_cmd.lib]

proc tk_CCX_DevConfig {txt} {

label .l1 -text $txt
button .b1 -text "Ok" -command "destroy ."
grid .l1 -row 2
grid .b1 -row 4 -column 0

}
...
...

# Call the above TK procedure

if [catch {tk_CCX_DevConfig "Plz configure Dev"} err] {
puts "Error in invoking Input Gui"
}

puts "User configuration is completed"

...
...

**********

the expected behavior should be .. tk window should pop up with following message "Plz configure Dev". And control has to go back to main script only when 'OK' is pressed.

But when i execute the above script, it popup a empty window and then control immediately goes back to main Tcl script ( it displays "User configuration is completed".

Could you please let me know how to transfer the control to the tk procedure and why the message is not getting displayed in tk widgets.

Thanks,
Kanna
 
I have no trouble running your proc. catch returns 0 as expected.

Therefore I suspect you are having a problem earlier in the script and furthermore, I suspect the source statements. I don't know what /opt/local/lib/controllerAp.lib and /opt/local/lib/contr_cli_cmd.lib are but from their names I suspect they are not Tcl scripts. source loads only script files that can be interpreted by Tcl. For binary files, which is what I would guess the .lib files are, you need load.

_________________
Bob Rashkin
 
Hi Rob,

Thanks for your reply. The files that are sourced are TCL files used by TCL main script on later stage. This tk procedure don't use those files listed in source. The tk procedure should work even if I remove those two source command.

Am I missing any tk commands or any env setting that needed for tk widgets to work?

Are you able to see the tk widget with message "Plz configure Dev" and 'OK' button on it ?

Does the control remains in tk widget ? does it transfer back to main tcl script only after pressing the OK button ?

- Kanna




 
When I ran your code (except for the source statements) I got the window with the label and the button. I think you have two problems.

The first, that you never see because of the second, is that when you pass control to the Wish interpreter, destroy . will exit Tcl altogether. This is because the toplevel window is, in fact, now the primary shell. To avoid this, I think you'd be better off just destroying the interior widgets (if you really feel the need to destroy something):
Code:
destroy .b1
destroy .l1

The second problem is that you're not actually passing control to the window; the script continues to execute. That is, you're only interrupting execution if the catch returns 1. I think for the purpose of just posting a message and waiting for a response, you should use a tk_messageBox:
NAME
tk_messageBox - pops up a message window and [red]waits[/red] for user response.
Perhaps something like:
Code:
proc tk_CCX_DevConfig {txt} {
    tk_messageBox -type ok -message $txt    
}

On the other hand, I suspect you are planning to extend the GUI to allow the user to input certain information. If that's the case, I'd use an explicit wait in the proc:
Code:
proc tk_CCX_DevConfig {txt} {
    [red]set d 0[/red]
    label .l1 -text $txt
    button .b1 -text "Ok"  -command "[red]set d 1[/red]"
    grid .l1 -row 2
    grid .b1 -row 4 -column 0
    [red]vwait d[/red]
}

_________________
Bob Rashkin
 
Hi Rob,

Thank you so much for your response. It works now.

Thank you so much again.

- Kanna
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top