home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dove!dove.nist.gov!przemek
- From: przemek@rrdstrad.nist.gov (Przemek Klosowski)
- Newsgroups: comp.lang.tcl
- Subject: variable visibility problem
- Message-ID: <PRZEMEK.92Nov17130700@rrdstrad.nist.gov>
- Date: 17 Nov 92 18:07:00 GMT
- Sender: news@dove.nist.gov
- Organization: U. of Maryland/NIST
- Lines: 50
-
- Hello!
-
- I am somehow new to Tcl, so I apologize if the answer to my question
- is obvious. It also may well be that there are better ways of
- accomplishing what I want, in a way that makes my question
- irrelevant---I ask for both answers and meta-answers.
-
- I have the following problem in my Tcl/Tk script. I have a button that
- opens up a canvas with a drawing. I want to be able to select a
- magnification of this drawing, so next to this button I keep a slider;
- I would select the zoom factor and then press the button that
- opens the canvas window. A first attempt at this code was:
-
- pack append $w.plot \
- [scale $w.plot.zoom -label Zoom: -from 1 -to 10 -orient horiz \
- -command "set zoomfac"] {right} \
- [button $w.plot.Qp -text "E-Q-space plot" -relief raised \
- -command "MyPlot $num $w $zoomfac"] {right}
-
- The scale widget sets the zoomfac local variable, and the button calls
- my canvas painting procedure MyPlot with three arguments, the last of
- which is the zoom factor. Since the scale -command is executed both
- when the widget is initialized and when the slider is moved, variable
- zoomfac is always initialized.
-
- Of course the code above does not work, because $zoomfac is evaluated
- once at the creation of button, and the MyPlot command is called with
- a constant argument. My second try was
-
- [button $w.plot.Qp -text "E-Q-space plot" -relief raised \
- -command {MyPlot $num $w $zoomfac}] {right}
-
- but this in turn fails, because $num is not a valid variable in the
- routine from which MyPlot is called.
-
- I ended up setting a global variable SomeVar, set by
-
- scale ... -command "set SomeVar"
-
- and read by MyPlot; but there oughta be a better way.
-
- Thanks for your help
- przemek
- --
- przemek klosowski (przemek@rrdstrad.nist.gov)
- Reactor Division (bldg. 235), E111
- National Institute of Standards and Technology
- Gaithersburg, MD 20899, USA
-
- (301) 975 6249
-