Getting the functionality of -command with tk_optionMenu (longish)
From: Gerry Snyder (gerrysnyder_at_comcast.net)
Date: 06/11/04
- Next message: T250: "bad socket results in child process exited abnormally"
- Previous message: SM Ryan: "Re: Add a reverse function?"
- Next in thread: Bruce Hartweg: "Re: Getting the functionality of -command with tk_optionMenu (longish)"
- Reply: Bruce Hartweg: "Re: Getting the functionality of -command with tk_optionMenu (longish)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 11 Jun 2004 02:18:35 GMT
I am writing a Tcl/Tk program to display a small database. In one window
I have a tk_optionMenu to choose the table, a scale to pick the row to
display, and a text window for the display. Whenever a new selection is
made on the optionMenu I want the scale and text to update, and when the
scale is moved I want the text to update. Code samples are shown below.
My first thought was to bind update commands to <ButtonRelease> events
on the optionMenu and scale. It works fine with the scale, giving the
expected result. Not so with the optionMenu, though. On W2k, Tcl 8.4,
the update command gets called, but with the "before" value of the
variable (menu0). Putting an after delay in the response command did
no good at all. Adding an update (menu1) almost did it, but once in a
while the old value is still used. Adding a vwait (menu2) on the
variable to the response makes sure the new value of the variable is
used, but that can hang up if the same value is selected again. Using
bindtags (menu3) to get the menu stuff before the added binding executes
did not help, but I could have used the wrong parameters.
However, this is not too relevant, perhaps, because on linux (RH 9, Tcl
8.3), the bind commands do not get called at all.
The way that does work on both platforms, is not using bind at all,
and just having a continuous vwait loop (menu4) controlling the
updates. The only problem with that in the current case is that if the
program is closed by the x icon at the top of the window the window
disappears but the program keeps running (Ctl-C kills it in linux, Task
Manager in W2k).
So, two questions:
1) Is there a way to do it using bind on both platforms? I prefer this
method, since it is easily extended to any number of widgets in a window.
2) Is there some modification of the vwait loop that will properly close
down if a user does not use the File-Exit way of closing the program?
TIA for any help.
Gerry
eval "tk_optionMenu .menu0 var0 a b c d e f"
eval "tk_optionMenu .menu1 var1 a b c d e f"
eval "tk_optionMenu .menu2 var2 a b c d e f"
eval "tk_optionMenu .menu3 var3 a b c d e f"
eval "tk_optionMenu .menu4 var4 a b c d e f"
label .label
pack .menu0 .menu1 .menu2 .menu3 .menu4 .label
bind .menu0 <ButtonRelease> {
.label configure -text $var0
}
bind .menu1 <ButtonRelease> {
update
.label configure -text $var1
}
bind .menu2 <ButtonRelease> {
vwait var2
.label configure -text $var2
}
bind .menu3 <ButtonRelease> {
.label configure -text $var3
bindtags .menu3 {Menubutton .menu3 . all}
}
while {1} {
vwait var4
.label configure -text $var4
}
- Next message: T250: "bad socket results in child process exited abnormally"
- Previous message: SM Ryan: "Re: Add a reverse function?"
- Next in thread: Bruce Hartweg: "Re: Getting the functionality of -command with tk_optionMenu (longish)"
- Reply: Bruce Hartweg: "Re: Getting the functionality of -command with tk_optionMenu (longish)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]