home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / tcl / 1855 < prev    next >
Encoding:
Internet Message Format  |  1992-11-17  |  2.2 KB

  1. Path: sparky!uunet!dove!dove.nist.gov!przemek
  2. From: przemek@rrdstrad.nist.gov (Przemek Klosowski)
  3. Newsgroups: comp.lang.tcl
  4. Subject: variable visibility problem
  5. Message-ID: <PRZEMEK.92Nov17130700@rrdstrad.nist.gov>
  6. Date: 17 Nov 92 18:07:00 GMT
  7. Sender: news@dove.nist.gov
  8. Organization: U. of Maryland/NIST
  9. Lines: 50
  10.  
  11. Hello!
  12.  
  13. I am somehow new to Tcl, so I apologize if the answer to my question
  14. is obvious. It also may well be that there are better ways of
  15. accomplishing what I want, in a way that makes my question
  16. irrelevant---I ask for both answers and meta-answers.
  17.  
  18. I have the following problem in my Tcl/Tk script. I have a button that
  19. opens up a canvas with a drawing. I want to be able to select a
  20. magnification of this drawing, so next to this button I keep a slider;
  21. I would select the zoom factor and then press the button that 
  22. opens  the canvas window. A first attempt at this code was:
  23.  
  24.     pack append $w.plot \
  25.           [scale $w.plot.zoom -label Zoom: -from 1 -to 10 -orient horiz \
  26.                            -command "set zoomfac"] {right} \
  27.       [button $w.plot.Qp -text "E-Q-space plot" -relief raised \
  28.                         -command "MyPlot $num $w $zoomfac"] {right}
  29.  
  30. The scale widget sets the zoomfac local variable, and the button calls
  31. my canvas painting procedure MyPlot with three arguments, the last of
  32. which is the zoom factor.  Since the scale -command is executed both
  33. when the widget is initialized and when the slider is moved, variable
  34. zoomfac is always initialized.
  35.  
  36. Of course the code above does not work, because $zoomfac is evaluated
  37. once at the creation of button, and the MyPlot command is called with
  38. a constant argument. My second try was
  39.  
  40.       [button $w.plot.Qp -text "E-Q-space plot" -relief raised \
  41.                         -command {MyPlot $num $w $zoomfac}] {right}
  42.  
  43. but this in turn fails, because $num is not a valid variable in the
  44. routine from which MyPlot is called.
  45.  
  46. I ended up setting a global variable SomeVar, set by 
  47.  
  48.  scale ...  -command "set SomeVar"
  49.  
  50. and read by MyPlot; but there oughta be a better way.
  51.  
  52. Thanks for your help
  53.             przemek
  54. --
  55.             przemek klosowski (przemek@rrdstrad.nist.gov)
  56.             Reactor Division (bldg. 235), E111
  57.             National Institute of Standards and Technology
  58.             Gaithersburg, MD 20899,      USA
  59.  
  60.             (301) 975 6249
  61.