home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / tcl / 2340 < prev    next >
Encoding:
Internet Message Format  |  1993-01-11  |  2.6 KB

  1. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!spool.mu.edu!agate!darkstar.UCSC.EDU!helios.UCSC.EDU!de
  2. From: de@helios.UCSC.EDU (De Clarke)
  3. Newsgroups: comp.lang.tcl
  4. Subject: Tk/Wish beginner seeks advice on use of text widget
  5. Date: 12 Jan 1993 02:32:38 GMT
  6. Organization: UCO/Lick Observatory
  7. Lines: 55
  8. Message-ID: <1itak6INNqr2@darkstar.UCSC.EDU>
  9. NNTP-Posting-Host: helios.ucsc.edu
  10. Summary: variable scoping in wish scripts seems weird?
  11.  
  12.  
  13. I can't figure out why the tcl executed with the -command flag from
  14. a wish script will recognize some variables but not others.
  15. For example, when the "load" button is pressed (see below), although
  16. text has been entered in the text widget $w.bot.raval, I get a tcl
  17. error no such variable.
  18.  
  19. sample code --------------
  20.     .....
  21.  
  22.     text $w.bot.raval -width 8 -height 1 -relief raised -border 1
  23.  
  24.     pack append $w.bot $w.bot.raval {left}
  25.  
  26.     button $w.bot.load -text "load" -command \
  27.         "set entry [${w.bot.raval} get 1.0 end]"
  28.  
  29.     .....
  30. ---------------------------
  31.  
  32. Before I put the curlies around $w.bot.raval, tcl complained
  33. about "w" being undefined -- couldn't handle the dots in the var name.
  34. Tcl appears to be allergic to variable names containing "." whereas
  35. wish uses them routinely.  [?]
  36.  
  37. or take this example:
  38.  
  39. button $w.bot.dismiss -text "go away" -command \
  40.     "puts stdout $var1; puts stdout $var2; destroy $w"
  41.  
  42. In this instance, var1 and var2 were correctly written to stdout,
  43. but window $w was not destroyed ("No such variable $w") -- however,
  44. when I split it into two buttons:
  45.  
  46. button $w.bot.show -text "show" -command "puts stdout $var1; puts stdout $var2"
  47. button $w.bot.dismiss -text "go away" -command "destroy $w"
  48.  
  49. then both buttons worked!  So what is so different about three commands
  50. separated by semicolons vs one command on its own?
  51.  
  52. Does anyone have a good theory about this?  I'm perplexed.
  53.  
  54. Or, alternatively, what is the best way in wish to prompt the user for a 
  55. very short text entry (like an integer format i3 or whatever)...?
  56. And how can I get their input into a tcl variable without needing
  57. another button-push to do so?  I can't find any example of this
  58. in the widget demos, though they cover almost everything else I
  59. would ever want to do.
  60.  
  61. email please, I doubt that the whole world is fascinated by my
  62. dumb beginner questions.
  63. ..............................................................................
  64. : De Clarke, Computing Resources Mgr.               UCO/Lick Observatory, UCSC :
  65. : de@helios.ucsc.edu |  Due to budgetary shortfalls, the light at the end of  :
  66. : de@portal.bitnet   |  the tunnel has been turned off.               --Anon  :
  67.