Scrollable buttons? 
Author Message
 Scrollable buttons?

Any possibilities to get buttons part of a scrolling canvas?

I have a lot of buttons to be displayed, and would like a scrollbar-feature
to deal with this. But buttons on a canvas is no good, is it?
I guess I could use rectangles on the canvas instead, but I kind of like the
3D appearance of the buttons.

I do not need to use a canvas of course, a frame will also do, but is it possible to scroll this?

Thank you for any and all replies!

Cheers
        Jostein



Sat, 06 May 1995 18:26:54 GMT  
 Scrollable buttons?

Quote:

>Any possibilities to get buttons part of a scrolling canvas?

>I have a lot of buttons to be displayed, and would like a scrollbar-feature
>to deal with this. But buttons on a canvas is no good, is it?
>I guess I could use rectangles on the canvas instead, but I kind of like the
>3D appearance of the buttons.

        You can do this.  Check out the demos that came with the
Tk distribution.  I was going to use this to implement a directory
viewer, but ran into some problems of my own with the canvas widget.

Here is the code that does this sort of thing :

frame .frame

scrollbar .frame.scroll \
    -command ".frame.canvas yview" \
    -relief raised

canvas .frame.canvas \
    -yscroll ".frame.scroll set" \
    -scrollregion {0 0 1200 10i} \
    -relief raised

pack append .frame \
    .frame.scroll    {left frame center filly} \
    .frame.canvas    {left frame center fillx filly}

pack append .\
    .frame   {left frame center fillx filly}

for {set i 0} {$i < 25} {incr i} {
    button .frame.canvas.button$i  \
        -relief raised \
        -text "Button $i"
    .frame.canvas create window 40 [expr $i*25] \
        -window .frame.canvas.button$i

Quote:
}

Run that through wish and watch what it does.

The problem I ran into was setting up the boundaries of the canvas.
I wanted to add and subtract buttons, and based on how many I had,
I needed to adjust the scrollregion height of the canvas and have the
scrollbars react accordingly.

So maybe at one point in my program's execution I had 20 buttons
lined up vertically, so my scrollregion needed to be :

    {0 0 200 [expr 25*20]}

and then I removed them all and reconfigured it so that there
were then 14 buttons.  So I want the scroll region to be :

   {0 0 200 [expr 25*14]}

The difficulty I encountered was that the scrollbars did not
react to my minstrations with the scroll region.  I tried doing
a manual set command on the scrollbar but was unsuccessfull in
sending it the proper arguments.

If anyone might know of a way to do this please tell me.  I am
afraid I could not figure it out.  

        -Michael

--
|\  Michael  Delbert  Moore     _   /|     Home   : (614) 471-1937         /|
| \ OSU Student  Programmer     \`o_O'     Office : (614) 292-7161        / |

|/-------------------------        U       --------------------------------\|



Sat, 06 May 1995 23:16:57 GMT  
 Scrollable buttons?
The hypertext widget (on barkley.berkeley.edu) can scroll buttons in a window.

The manpage for the text widget (standard in Tk) says that the ability to
include arbitrary windows within text widgets will be available in a future
release.
--

"Turn on your hot tub by email now.  Ask me how."



Sat, 06 May 1995 21:47:36 GMT  
 Scrollable buttons?

[ A bunch of code to make a frame with a canvas and a scrollbar... ]

Quote:
> for {set i 0} {$i < 25} {incr i} {
>    button .frame.canvas.button$i  \
>    -relief raised \
>    -text "Button $i"
>    .frame.canvas create window 40 [expr $i*25] \
>    -window .frame.canvas.button$i
> }

The problem here is that you have to know the size of the buttons
beforehand.  Could you do the following?  (I haven't tried it but I
will.)

- make a canvas with a scrollbar
- put a frame somewhere in the canvas
- pack all the buttons in the frame
- see how big the frame is
- set the canvas scroll region appropriately

Has anybody written a scrolled frame?  That ought to be an easy widget
to write.  (I know, why don't I write it...)

        Wayne



Sun, 07 May 1995 03:15:39 GMT  
 Scrollable buttons?
I'm putting windows on (in?) a canvas for an application I'm writing.
It's not trivial, but it's not too hard, either.  

- Use winfo reqheight/reqwidth to figure out how big the window will
  be.  Then you can use whatever placement algorithm you want.  I just
  place my windows in rows, with a "return" whenever a window
  threatens to overrun the (current) right edge of the canvas (as
  determined by 'winfo width <canvas>').

- After placing all the windows, make sure the scrolling region is big
  enough.

- All events inside the window go to the window, NOT the canvas.  This
  is a pain if you want to be able to drag the windows.  I use code
  like this:

    bind $w <3> "itemStartDrag $theCanvas \[expr %x+\[winfo x $w]]\
                                    \[expr %y+\[winfo y $w]]";
    bind $w <B3-Motion> "itemDrag $theCanvas \
                                    \[expr %x+\[winfo x $w]]\
                                    \[expr %y+\[winfo y $w]] $tag";
    bind $f <Any-Enter> "itemEnter $theCanvas $field";
    bind $f <Any-Leave> "itemLeave $theCanvas";
  where $w is the window name, and $tag is a tag for the window.
  itemEnter for a window "raises" it (in relief).

--
=Spencer W. Thomas              |  Info Tech and Networking, B1911 CFOB, 0704
   "Genome Informatician"     |  Univ of Michigan, Ann Arbor, MI 48109



Mon, 08 May 1995 11:18:42 GMT  
 Scrollable buttons?

Quote:
> - Use winfo reqheight/reqwidth to figure out how big the window will
>   be.

Sigh.  I got ahead of myself here.  Only some windows get reqheight
and reqwidth right before they're realized (X technical term).  I
tested it with a label, and it worked.  However, a form with a label
and an entry inside it gives back reqheight/width of 0 until the next
update.  I came up with this, which does work in my application.  It's
better than my previous solution, which stacked all the windows at 0,0
and then shuffled them to the appropriate final location.

        <Create windows, make a list of window names>

        update
        # Note that the windows are not visible because they haven't
        # been placed on the canvas yet.  But they do have a real
        # height and width now.

        foreach w $windowlist {
                <Compute appropriate x/y position>
                canvas create window $x $y -window $w ....
        }

--
=Spencer W. Thomas              |  Info Tech and Networking, B1911 CFOB, 0704
   "Genome Informatician"     |  Univ of Michigan, Ann Arbor, MI 48109



Tue, 09 May 1995 23:58:07 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. identifying button in scrollable buttons

2. Tkinter: Scrollable buttons

3. Need help with scrollable buttons

4. Scrollable Listbox of Buttons

5. coordinates of a button event in a scrollable canvas

6. How can I create a scrollable window of buttons

7. scrollable list of buttons ?

8. Button, Button, who's got the Button?

9. A button disables after another button is finished..

10. C4: Merged button showing up way to the right of the other buttons

11. left mouse button = right mouse button

12. Radio Buttons & Change Button

 

 
Powered by phpBB® Forum Software