home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / tcl / 1850 < prev    next >
Encoding:
Text File  |  1992-11-17  |  2.9 KB  |  89 lines

  1. Newsgroups: comp.lang.tcl
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!stegosaur.cis.ohio-state.edu!mdm
  3. From: mdm@stegosaur.cis.ohio-state.edu (Michael Moore)
  4. Subject: Re: Scrollable buttons?
  5. Message-ID: <1992Nov17.151657.3467@cis.ohio-state.edu>
  6. Sender: news@cis.ohio-state.edu (NETnews        )
  7. Organization: The Ohio State University Dept. of Computer and Info. Science
  8. References: <1992Nov17.102654.15449@dxcern.cern.ch>
  9. Date: Tue, 17 Nov 1992 15:16:57 GMT
  10. Lines: 77
  11.  
  12. In article <1992Nov17.102654.15449@dxcern.cern.ch> trones@dxcern.cern.ch (Jostein Lodve Trones) writes:
  13. >
  14. >Any possibilities to get buttons part of a scrolling canvas?
  15. >
  16. >I have a lot of buttons to be displayed, and would like a scrollbar-feature
  17. >to deal with this. But buttons on a canvas is no good, is it?
  18. >I guess I could use rectangles on the canvas instead, but I kind of like the
  19. >3D appearance of the buttons.
  20. >
  21.  
  22.     You can do this.  Check out the demos that came with the
  23. Tk distribution.  I was going to use this to implement a directory
  24. viewer, but ran into some problems of my own with the canvas widget.
  25.  
  26. Here is the code that does this sort of thing :
  27.  
  28. frame .frame
  29.  
  30. scrollbar .frame.scroll \
  31.     -command ".frame.canvas yview" \
  32.     -relief raised
  33.  
  34. canvas .frame.canvas \
  35.     -yscroll ".frame.scroll set" \
  36.     -scrollregion {0 0 1200 10i} \
  37.     -relief raised
  38.  
  39. pack append .frame \
  40.     .frame.scroll    {left frame center filly} \
  41.     .frame.canvas    {left frame center fillx filly}
  42.  
  43. pack append .\
  44.     .frame   {left frame center fillx filly}
  45.  
  46. for {set i 0} {$i < 25} {incr i} {
  47.     button .frame.canvas.button$i  \
  48.     -relief raised \
  49.     -text "Button $i"
  50.     .frame.canvas create window 40 [expr $i*25] \
  51.     -window .frame.canvas.button$i 
  52. }
  53.  
  54.  
  55. Run that through wish and watch what it does.
  56.  
  57. The problem I ran into was setting up the boundaries of the canvas.
  58. I wanted to add and subtract buttons, and based on how many I had,
  59. I needed to adjust the scrollregion height of the canvas and have the 
  60. scrollbars react accordingly.
  61.  
  62. So maybe at one point in my program's execution I had 20 buttons
  63. lined up vertically, so my scrollregion needed to be :
  64.     
  65.     {0 0 200 [expr 25*20]}
  66.  
  67. and then I removed them all and reconfigured it so that there
  68. were then 14 buttons.  So I want the scroll region to be :
  69.  
  70.    {0 0 200 [expr 25*14]}
  71.  
  72. The difficulty I encountered was that the scrollbars did not
  73. react to my minstrations with the scroll region.  I tried doing
  74. a manual set command on the scrollbar but was unsuccessfull in
  75. sending it the proper arguments.
  76.  
  77. If anyone might know of a way to do this please tell me.  I am
  78. afraid I could not figure it out.  
  79.  
  80.  
  81.         -Michael
  82.  
  83.  
  84. -- 
  85. |\  Michael  Delbert  Moore     _   /|     Home   : (614) 471-1937         /|
  86. | \ OSU Student  Programmer     \`o_O'     Office : (614) 292-7161        / |
  87. | / Undergraduate CIS major       ( )      Email  : mdm@cis.ohio-state.edu\ |
  88. |/-------------------------        U       --------------------------------\|
  89.