From: vinay s on
Hi All,

I am trying to add buttons in the frame Using TCL/Tk language. I am
able to create frame and add button in it. The problem is that, if i
am keep adding the buttons in the frame then they will not appear in
the frame after some count, I wanted them to come in the next line
once it reaches to frame size.
Please advise me, what should i do to solve the problem. Thanks in
advance.
My code snip:
====
wm title . "Toolbar Demonstration"
wm geometry . 325x100

set count 0
proc add_frame title {
global frame count w
set frame .frame$count
frame $frame -border 2 -relief groove
label $frame.label -text $title
pack $frame -side left -padx 2 -pady 2 -anchor n -fill x
pack $frame.label -side top -padx 2 -pady 2
incr count
}
proc add_button {title} {
global frame count
button $frame.$count -text $title
pack $frame.$count -side left -pady 1 -padx 3 -fill x
incr count
}

add_frame "Button Set1"
add_button " B1 "
add_button " B2 "
add_button " B3 "
add_button " B4 "
add_button " B5 "
add_button " B6 "
add_button " B7 "
add_button " B8 "
add_button " B9 "

=====
From: Uwe Klein on
vinay s wrote:
> Hi All,
>
> I am trying to add buttons in the frame Using TCL/Tk language. I am
> able to create frame and add button in it. The problem is that, if i
> am keep adding the buttons in the frame then they will not appear in
> the frame after some count, I wanted them to come in the next line
> once it reaches to frame size.
> Please advise me, what should i do to solve the problem. Thanks in
> advance.
> My code snip:
> ====
> wm title . "Toolbar Demonstration"
> wm geometry . 325x100
>
> set count 0
> proc add_frame title {
> global frame count w
> set frame .frame$count
> frame $frame -border 2 -relief groove
> label $frame.label -text $title
> pack $frame -side left -padx 2 -pady 2 -anchor n -fill x
> pack $frame.label -side top -padx 2 -pady 2
> incr count
> }
> proc add_button {title} {
> global frame count
> button $frame.$count -text $title
> pack $frame.$count -side left -pady 1 -padx 3 -fill x
> incr count
> }
>
> add_frame "Button Set1"
> add_button " B1 "
> add_button " B2 "
> add_button " B3 "
> add_button " B4 "
> add_button " B5 "
> add_button " B6 "
> add_button " B7 "
> add_button " B8 "
> add_button " B9 "
>
> =====
A: Use subframes for button rows
B: Use the grid geometry manager, increment the row value every couple of buttons.
C: use the text widget and fill it with windows ( here buttons ), see example:

#!/usr/bin/wish

# create and pack a text widget:
text .t ; pack .t

# do 50 buttons programaticaly:
for {set i 0} {$i<50} {incr i} {
# create a button widget:
button .b$i -text [string totitle b$i ] -command "button $i pressed"
# insert this widget at the end of the text widget content:
.t window create end -window .b$i
}
# voila:

uwe