Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

usage of checkbutton

28 views
Skip to first unread message

krith...@yahoo.com

unread,
May 3, 2006, 5:23:52 PM5/3/06
to
Hello
I am trying to create a form with a label and a YES and NO check
box. I am using Checkbutton with a text "YES" but it is not displaying
the text. How do I create another Checkbutton with a NO ?

I am sending part of my code

proc display_screen {} {
global fields data

# remove any existing form
reset_form


# widgets have a part number ending in "1"; gadgets are all others
set serialnum $data(serialnum)
if {[string match {*1} [string trim $serialnum]]} {
set type "form1"
} else {
set type "form2"
}


set frame .form-$type
set data(type) $type


# Only create the form if it doesn't already exist
if {![winfo exists $frame]} {
frame $frame -borderwidth 2 -relief groove
foreach field $fields($type) {
label $frame.l-$field -text "$field:"
#entry $frame.e-$field -textvariable data($field)

checkbutton $frame.e-$field -text "YES" -textvariable
data($field)

grid $frame.l-$field $frame.e-$field
grid configure $frame.l-$field -sticky e
grid configure $frame.e-$field -sticky ew
# have <Return> perform the same behavior of <Tab>
# bind $frame.e-$field <Return> [bind all <Tab>]
}
set lastrow [lindex [grid size $frame] 1]
grid rowconfigure $frame $lastrow -weight 1
grid columnconfigure $frame 1 -weight 1
}

Thanks
kc

Simon Bachmann

unread,
May 3, 2006, 5:49:05 PM5/3/06
to
krith...@yahoo.com wrote:
> Hello
> I am trying to create a form with a label and a YES and NO check
> box. I am using Checkbutton with a text "YES" but it is not displaying
See the correction in the code

> the text. How do I create another Checkbutton with a NO ?
If I understood correctly what you want, you'd best use radiobuttons:

radiobutton .yes -text Yes -variable switch_var -value 1
radiobutton .no -text No -variable switch_var -value 0

whenever a radiobutton is selected, it assings the specified -value (0
or 1 in this case, but it can be any string) to the specified -variable
(switch_var in the example). It also selects/deselects itself whenever
the variable changes and corresponds/differs from value.
See also "man radiobutton."


>
> I am sending part of my code
>
> proc display_screen {} {
> global fields data
>
> # remove any existing form
> reset_form
>
>
> # widgets have a part number ending in "1"; gadgets are all others
> set serialnum $data(serialnum)
> if {[string match {*1} [string trim $serialnum]]} {
> set type "form1"
> } else {
> set type "form2"
> }
>
>
> set frame .form-$type
> set data(type) $type
>
>
> # Only create the form if it doesn't already exist
> if {![winfo exists $frame]} {
> frame $frame -borderwidth 2 -relief groove
> foreach field $fields($type) {
> label $frame.l-$field -text "$field:"
> #entry $frame.e-$field -textvariable data($field)
>
> checkbutton $frame.e-$field -text "YES" -textvariable
> data($field)

From the manpage of checkbutton:

"Command-Line Name:-textvariable

Specifies the name of a variable. The value of the variable is a text
string to be displayed inside the widget; if the variable value
changes then the widget will automatically update itself to reflect
the new value. The way in which the string is displayed in the widget
depends on the particular widget and may be determined by other options,
such as anchor or justify.

What you probably want is "-variable"

Bryan Oakley

unread,
May 3, 2006, 6:08:21 PM5/3/06
to
krith...@yahoo.com wrote:
> Hello
> I am trying to create a form with a label and a YES and NO check
> box. I am using Checkbutton with a text "YES" but it is not displaying
> the text.

You are confusing "-variable" with "-textvarible". Use -textvariable if
you want to associate a variable with the text on the screen, use
-variable to associate a variable with the value of the widget. If you
use -textvariable, that will override the -text option.

> How do I create another Checkbutton with a NO ?

The same way you create the one with the yes. Give it a different
pathname and a different value for the -text option.

checkbutton $frame.e1-$field -text "YES" ...
checkbutton $frame.e2-$field -text "NO" ...

BTW, if you are creating a set of widgets that represent one of two
states, you should use radiobuttons rather than checkbuttons.

With radiobuttons, assuming you've defined them correctly, if you click
YES, NO will automatically be unclicked and visa versa. If you use
checkbuttons it will be possible to have both YES and NO checked at the
same time and your users will be confused.

radiobutton $frame.e1-$field -value yes -text YES \
-variable data($field)
radiobutton $frame.e2-$field -value no -text NO \
-variable data($field)

--
Bryan Oakley
http://www.tclscripting.com

Bruce Hartweg

unread,
May 3, 2006, 6:49:12 PM5/3/06
to
An alternative to two radio buttons, is to stick with a checkbutton
and use *both* -vat and -textvar to update text as well as check state

checkbutton $btn -textvar VAR -var VAR -onval Yes -offval No

Bruce

Bryan Oakley

unread,
May 3, 2006, 7:04:31 PM5/3/06
to
Bruce Hartweg wrote:

> An alternative to two radio buttons, is to stick with a checkbutton
> and use *both* -vat and -textvar to update text as well as check state
>
> checkbutton $btn -textvar VAR -var VAR -onval Yes -offval No

While I agree a single checkbutton for yes/not is often better than two
radiobuttons (if the text is sufficiently descriptive), I would argue
that linking the -variable and -textvariable is bad UI design.

Consider the unchecked state. In the unchecked state it would look like
this:

[ ] NO

That to me implies that if I check it I get the "NO" behavior. But, when
I check "NO" I actually get "YES". That would be very confusing.

Bruce Hartweg

unread,
May 4, 2006, 11:19:14 AM5/4/06
to

I agree - generally I would have the text be static and descriptive
of the item in question and let the checks themselves speak to the
yes/no state. But I was just mentioing it since the OP asked about
changing the values of the text itself that it *is* possible if that's
what you really want


> --
> Bryan Oakley
> http://www.tclscripting.com

BTW - nice job you're doing with this site - keep it up!

Bruce

krith...@yahoo.com

unread,
May 12, 2006, 7:06:02 PM5/12/06
to
Hi
Thanks. I am trying to use the variable associated with the
radiobutton as

set MN $data($field) to determine if YES was selected or No was
selected for that field.
But when I display $MN it is empty though I click YES and NO after the
screen is displayed. Why is this empty?

Thanks
kc

Bryan Oakley

unread,
May 12, 2006, 7:38:43 PM5/12/06
to
Without seeing your code we have no way of helping you.

Try this in an interactive wish shell:

set field "foo"
radiobutton .yes$field -variable data($field) -value 1 -text Yes
radiobutton .no$field -variable data($field) -value 0 -text No
pack .yes$field .no$field

Now, click one of the radiobuttons then do the following at the prompt:

puts "value is $data($field)"

You can accomplish the same thing with a single checkbutton:

checkbutton .cb$field -onvalue 1 -offvalue 0 -text Yes? \
-variable data($field)
pack .cb$field

Notice that if you have both the checkbutton and the two radiobuttons
they stay in sync because they all share the same variable.

Does that help?

krith...@yahoo.com

unread,
May 12, 2006, 7:58:16 PM5/12/06
to
Hi
Thanks. This is part my code

radiobutton $frame.e1-$field -value yes -text YES -variable
data($field) -padx 0 -font {ariel 12 bold}

radiobutton $frame.e2-$field -value no -text NO -variable
data($field) -padx 0 -font {ariel 12 bold}
puts "value is $data($field)"

I am associating a field with YES and NO within a frame. When I display
value it is empty
Of course I have not clicked YES or NO. Do I need to bind these . Let
me know

Thanks
krithiga

Cameron Laird

unread,
May 12, 2006, 8:05:16 PM5/12/06
to
In article <1147475162.8...@i40g2000cwc.googlegroups.com>,

<krith...@yahoo.com> wrote:
>Hi
> Thanks. I am trying to use the variable associated with the
>radiobutton as
>
>set MN $data($field) to determine if YES was selected or No was
>selected for that field.
>But when I display $MN it is empty though I click YES and NO after the
>screen is displayed. Why is this empty?
.
.
.
Probably because you
set MN $data($field)
after the GUI has been realized, but before a user has made
a selection. Are you *sure* you execute that assignment
after the selection--not after the buttons have been defined,
but after they've been used?

Bryan Oakley

unread,
May 12, 2006, 9:46:18 PM5/12/06
to

You need to configure the -value option of each radiobutton.

http://www.tcl.tk/man/tcl8.4/TkCmd/radiobutton.htm#M14

Message has been deleted

Donald Arseneau

unread,
May 13, 2006, 12:47:38 AM5/13/06
to
krith...@yahoo.com writes:

> Thanks. This is part my code
> radiobutton $frame.e1-$field -value yes -text YES -variable
> data($field) -padx 0 -font {ariel 12 bold}
> radiobutton $frame.e2-$field -value no -text NO -variable
> data($field) -padx 0 -font {ariel 12 bold}
> puts "value is $data($field)"

That is the correct part of your code (assuming your news-reader
introduced the linebreaks).

> When I display value it is empty

What value is empty? $data($field)? If you displayed it in a
proc, did you declare data to be global in that proc?

> Of course I have not clicked YES or NO.

OH! If you haven't clicked anything to select a value, and
you haven't assigned a value, how could there be a value?

You can initialize the value by assigning the variable:

set data($field) "YES"

or selecting the radiobutton

$frame.e1-$field invoke


> Do I need to bind these

No. But if you need some advanced side-effects, you should
do that with the -command option. You mentioned looking at
another variable NM (?) previously, so you could specify:

radiobutton $frame.e1-$field ... -command "set NM \$data($field)"

Note that the value of $field is substituted when the radiobutton
is created, but $data() is substituted when you invoke the command.

--
Donald Arseneau as...@triumf.ca

krith...@yahoo.com

unread,
May 17, 2006, 1:58:16 PM5/17/06
to
Hi
Thanks. How do I set a default value for the button. Is it possible
to have YES clicked and the user can change it to NO?

Thanks
kc

Bryan Oakley

unread,
May 17, 2006, 2:08:10 PM5/17/06
to

Just set the variable associated with the button:

set data(foo) 1
checkbutton .foo -variable data(foo) -text "Foo?" \
-onvalue 1 -offvalue 0
pack .foo

krith...@yahoo.com

unread,
May 18, 2006, 2:29:53 PM5/18/06
to
Hello
Thanks for the reply

I am also tryinbg to add an NA with the field

checkbutton $frame.e1-$FN -onvalue yes -offvalue no -text YES
-variable data($FN) -padx 0 -font {ariel 12 bold}
checkbutton $frame.e2-$FN -text NO -variable data($FN) -padx 0
-font {ariel 12 bold}
checkbutton $frame.e3-$FN -text NA -variable data($FN) -padx 0
-font {ariel 12 bold}'
When I do this nothing is shown on the screen

pack $frame.e1-$FN $frame.e2-$FN $frame.e3-$FN
grid configure $frame.e1-$FN $frame.e2-$FN $frame.e3-$FN -sticky ew

What am I missing?

Thanks
krithiga

Bryan Oakley

unread,
May 18, 2006, 2:52:30 PM5/18/06
to

You are mixing grid and pack. Don't do that. Either use grid, or use
pack, but don't use them both in the same frame.

If you are trying to give the user the choice of one of three states,
don't use checkbuttons. That is the wrong widget and will confuse many
users. Use radiobuttons; they are designed to be used as a group for an
exclusive choice. The visual differences between radiobuttons and
checkbuttons is purposeful, and gives the users clues as to how they behave.

Either use a single checkbutton for yes/no, or use three radiobuttons
for yes/no/na. You should never* use two checkbuttons to represent two
(or more) values for the same variable.

* "never" is maybe a bit strong, but unless you really have a good,
proven reason to break the rule, "never" is a pretty good guideline.

krith...@yahoo.com

unread,
May 18, 2006, 3:32:04 PM5/18/06
to
Hi
Thanks
But if use radiobutton , how can I have default values of YES for
everything. Only with checkbutton you can use onvalue. With radiobutton
we cannout use on value and off value. How do you setdefault for a
radiobutton?

Thanks
kc

Bryan Oakley

unread,
May 18, 2006, 4:23:14 PM5/18/06
to

A radiobutton corresponds to a single value. If the value of the
variable is the same as the value for the radiobutton, the radiobutton
will be selected.

You have three values (yes, no, na) so you use three radiobuttons. All
three are tied to the same variable, so whichever radiobutton
corresponds to the current value will be set.

I recommend you spend a few minutes in a tcl console experimenting.

here's a quick example:

radiobutton .rb1 -variable foo -value 1 -text One
radiobutton .rb2 -variable foo -value 2 -text Two
radiobutton .rb3 -variable foo -value 3 -text Three
set foo 2
pack .rb1 .rb2 .rb3

You can change that "set foo 2" to set the value to 1, 2 or 3 depending
on which radiobutton you want selected. You can set it to anything else
to have none of the radiobuttons selected by default.

Donald Arseneau

unread,
May 18, 2006, 4:55:15 PM5/18/06
to
krith...@yahoo.com writes:

What you have makes no sense at all, so it is hard to guess what
you really want. You have no onvalue or offvalue for two of the
checkbuttons. Whatever you are attempting, I don't think multiple
checkbuttons sharing the same variable will be useful.

The easiest way to set a default for both checkbutton and radiobutton
is to set the associated variable.


--
Donald Arseneau as...@triumf.ca

krith...@yahoo.com

unread,
May 18, 2006, 5:03:12 PM5/18/06
to
Hi
OK this example I experimented it set the three radiobuttons to YES
NO and NA but I set foo YES and YES was not checked in the example.

I used this in my code.
radiobutton $frame.e1-$FN -variable data($FN) -value yes -text YES
radiobutton $frame.e2-$FN -variable data($FN) -value no -text NO
radiobutton $frame.e3-$FN -variable data($FN) -value na -text NA
set data($FN) yes

pack $frame.e1-$FN $frame.e2-$FN $frame.e3-$FN

The code hangs if set $frame.e3 in the pack

If I do not use NA it shows as YES checked and is OK. What is wrong
here?

Thanks
kc

krith...@yahoo.com

unread,
May 18, 2006, 5:06:07 PM5/18/06
to
What i am trying to accomplish is have a YES NO and NA for each of the
fields with YES checked as default. Was I coding correctly?

Thanks
kc

Cameron Laird

unread,
May 18, 2006, 4:27:22 PM5/18/06
to

Gerald W. Lester

unread,
May 18, 2006, 5:24:44 PM5/18/06
to

YES is not the same as yes. If you want YES checked according to the code
above, you need to set foo to yes -- not to YES.

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+

Bruce Hartweg

unread,
May 18, 2006, 5:28:08 PM5/18/06
to
krith...@yahoo.com wrote:
> Hi
> OK this example I experimented it set the three radiobuttons to YES
> NO and NA but I set foo YES and YES was not checked in the example.
>

are you using foo or data(%NF) and are you setting it to yes or YES?

> I used this in my code.
> radiobutton $frame.e1-$FN -variable data($FN) -value yes -text YES
> radiobutton $frame.e2-$FN -variable data($FN) -value no -text NO
> radiobutton $frame.e3-$FN -variable data($FN) -value na -text NA
> set data($FN) yes

is this inside a proc? if so is data defined as a global in this proc?

>
> pack $frame.e1-$FN $frame.e2-$FN $frame.e3-$FN
>
> The code hangs if set $frame.e3 in the pack
>

please explain further - show complete code of example that "hangs"

> If I do not use NA it shows as YES checked and is OK. What is wrong
> here?

without seeing complete code I can't tell you

Bruce

krith...@yahoo.com

unread,
May 18, 2006, 5:32:56 PM5/18/06
to
Hi
The code is hanging when I use the radiobuttons as above. What did I
code incorrectly?

Thanks
krithiga

krith...@yahoo.com

unread,
May 18, 2006, 5:37:18 PM5/18/06
to
Here is the procedure

proc display {} {
global fields data type lat field FN

set serialnum $data(serialnum)

set type "OQA"


set frame .form-$type
set data(type) $type

set LastItem [lindex $fields($type) end]
puts $LastItem


# Only create the form if it doesn't already exist
if {![winfo exists $frame]} {
frame $frame -borderwidth 2 -relief groove
foreach field $fields($type) {

label $frame.l-$field -text "$field:" -padx 0 -font {ariel 14
bold}
entry $frame.e-$field -textvariable lat($field)

foreach FN $fields($field) {
puts "field is $FN"
label $frame.l1-$FN -text "$FN:" -padx 0 -font {ariel 14 bold}
if { $field == "Cosmetics" } {
puts " I am in Cosmetics"
#set data($FN) no
checkbutton $frame.e1-$FN -text YES -variable data($FN) -padx 0
-font {ariel 12 bold}
checkbutton $frame.e2-$FN -onvalue no -offvalue yes -text NO


-variable data($FN) -padx 0 -font {ariel 12 bold}

} else {


radiobutton $frame.e1-$FN -variable data($FN) -value yes -text YES
radiobutton $frame.e2-$FN -variable data($FN) -value no -text NO
radiobutton $frame.e3-$FN -variable data($FN) -value na -text NA
set data($FN) yes

}
pack $frame.e1-$FN $frame.e2-$FN $frame.e3-$FN


grid $frame.l-$field
grid $frame.l1-$FN $frame.e1-$FN $frame.e2-$FN $frame.e3-$FN
grid configure $frame.l1-$FN -sticky e


}
}
set lastrow [lindex [grid size $frame] 1]
grid rowconfigure $frame $lastrow -weight 1
grid columnconfigure $frame 1 -weight 1
}

# make sure this form is the one that is visible
pack $frame -in .form -side top -after .serialnum -fill both -expand y

raise $frame
update idletasks

}
I had to use grid and pack as I do not use grid nothing shows on the
screen

Thanks
kc

Bryan Oakley

unread,
May 18, 2006, 5:58:03 PM5/18/06
to
krith...@yahoo.com wrote:
> pack $frame.e1-$FN $frame.e2-$FN $frame.e3-$FN
> ...
>
>
>
> grid $frame.l-$field

Like I said earlier, you cannot use grid and pack in the same frame.
That will cause your program to hang or act very strange.

Use one or the other.

krith...@yahoo.com

unread,
May 18, 2006, 7:29:25 PM5/18/06
to
Hi
But when I use it without the frame3 it is working fine. IF I do not
use grid it is a blank screen

Thanks
krithiga

Donald Arseneau

unread,
May 18, 2006, 7:51:24 PM5/18/06
to
krith...@yahoo.com writes:

> What i am trying to accomplish is have a YES NO and NA for each of the
> fields with YES checked as default. Was I coding correctly?

You say "each of the fields", but I don't know what a "field" is
in your application. This would make sense to me if you had three
different varibles, and each variable could have any of those
values independent of the other two variables.

Is there one single question whose answer is (one and only one of)
YES, NO, or NA?

Based on the answers alone, that's what I'm assuming.

Starting with Tk 8.5 there is a new -tristate checkbutton to facilitate
such triple-barrel answers (though the lobby to extend checkbutton
that way was more interested in "All, None, Some"). But 8.5 is not
released yet.

The way we've handled triple-state variables until 8.5 (and beyond too)
is with three radiobuttons plus a label (or possibly a labelled frame),
looking like

Have you had your prescription checked
in the last year:
[ ] Yes
[ ] No
[O] NA


Where clicking on any answer *moves* the indicator.

I would implement this like:


frame .prescrip -borderwidth 2 -relief groove -padx 2 -pady 2
label .prescrip.question -wraplength 200 -justify l -anchor w \
-text "Have you had your prescription checked in the last year:"
radiobutton .prescrip.yes -text Yes -padx 20 \
-variable data(prescrip) -value YES
radiobutton .prescrip.no -text No -padx 20 \
-variable data(prescrip) -value NO
radiobutton .prescrip.na -text NA -padx 20 \
-variable data(prescrip) -value NA

# This is the default:
set data(prescrip) NA

pack .prescrip.question .prescrip.yes .prescrip.no .prescrip.na -anchor w
pack .prescrip -padx 5 -pady 5

# And some indication of what this demo is doing:

label .l -text "The value of data(prescrip):"
label .p -textvariable data(prescrip)

pack .l .p -anchor w

--
Donald Arseneau as...@triumf.ca

krith...@yahoo.com

unread,
May 18, 2006, 8:22:06 PM5/18/06
to
Hi
In the code I have I did the same way except I used frames instead of
.prescrip. I have may fields eg

set fields(OQA) { Manual_Kit Software_Kit QSG Accessories Cosmetics
Match}
set fields(Manual_Kit) {RM_FIRST DEC_OF_CONFOR Safety_statement}

I set form to OQA and then I used the foreach loop to assign YES NO NA
for each of these fields. What I am i doing incorrect in my code that
it is hanging?

Thanks
kc

Bryan Oakley

unread,
May 18, 2006, 9:25:54 PM5/18/06
to

I'll repeat what I said earlier: if you use grid and pack in the same
frame, your code will almost certainly hang.

Bryan Oakley

unread,
May 18, 2006, 9:26:43 PM5/18/06
to
krith...@yahoo.com wrote:
> Here is the procedure
> ...

> pack $frame.e1-$FN $frame.e2-$FN $frame.e3-$FN
>
>
>
>
> grid $frame.l-$field
> grid $frame.l1-$FN $frame.e1-$FN $frame.e2-$FN $frame.e3-$FN
> grid configure $frame.l1-$FN -sticky e
> }
> }
> set lastrow [lindex [grid size $frame] 1]
> grid rowconfigure $frame $lastrow -weight 1
> grid columnconfigure $frame 1 -weight 1
> }
> }
> I had to use grid and pack as I do not use grid nothing shows on the
> screen

When you say you "do not use grid", do you mean you take "grid
$frame.l1-$FN ..." out and replace it with an appropriate pack command?
Nowhere else in your code do you pack $frame.e1-$FN, so if you simply
comment out the grid statements of course you won't see the labels. You
will, however, see other items you've packed. At least, when I took your
code and ran it I saw a bunch of radiobuttons.

You're struggling with some very, very basic logic here and I'm not sure
how best to help you. You seem to prefer pack, but grid is the more
natural choice for laying out this type of form. Either grid or pack can
work, though pack requires more intermediate frames than you are using.

Am I correct that this is the layout you are trying to create? (I hope
you have a fixed font in your news reader...)

<field 1>: [________________________________________]
<sub-field a>: <> YES <> NO <> NA
<sub-field b>: <> YES <> NO <> NA
<sub-field c>: <> YES <> NO <> NA
<field 2>: [________________________________________]
<sub-field a>: <> YES <> NO <> NA
<sub-field b>: <> YES <> NO <> NA
<sub-field c>: <> YES <> NO <> NA

I'm going to assume that is accurate. As you can see, it easily can be
divided into four or five columns. The subfields have a label, yes, no
and na radiobutton. The other rows have a label and an entry widget that
should just fill the width of the form (I'm guessing...)

Since you are new to GUI development I recommend you always try to draw
your forms out on paper like this, preferably on graph paper. You can
then draw boxes or rows and columns depending on whether you're using
pack or grid.

With the above we can easily see four rows. From experience, I know that
it's useful to always dedicate one row and one column to be the one that
takes up any extra space. The question is, which row and which column?

You can use an existing row and column if it's something that would
benefit from growing or shrinking (for example, a text widget, canvas,
or an entry widget), or you can use an invisible row or column.

In this case we can use an invisible column to the right of the NA
buttons. The entry widget can expand into that column so that it can be
as wide as the whole form, and grow or shrink as appropriate. Thus, our
columns look like this:

| column 0 | col 1 | col 2 | col 3 | column 4 |
<field 1>: [________________________________________]
<sub-field 1>: <> YES <> NO <> NA


With that layout in mind, lets look at how to create it. The following
code won't work if you paste it into a file, and it sacrifices
efficiency for readability. And bear in mind, this is just off the top
of my head so there may be some minor typos or mistakes. Hopefully
though, you can take it and make a working program out of it.

The first part is creating the first row. Notice from the above diagram
that the entry widget actually stretches from column 1 to column 4. This
code assumes the existance of a frame named $f which will contain all
the widgets, and $type and $fields has been defined:

# iterate over each field for the given type
foreach field $type {

# here we create the label and entry
label $f.l$field -text "$field:" ...
entry $f.e$field ...

# and here we explicitly place it in a specific row and column
# notice how the entry widget is told to span 4 columns
grid $f.l$field -row 0 -column 0 -sticky e
grid $f.e$field -row 0 -column 1 -columnspan 4 -sticky ew

Now for the second part, creating the subfields for each field. It looks
a lot like the above, though we have to compute the row rather than
hard-coding it, and obviously we are creating radiobuttons rather than a
single entry widget:

set row 0
foreach subfield $fields($field) {
# place these widgets on the next row
incr row

# create the label and the radiobuttons
label $f.l$subfield -text "$subfield:" ...
radiobutton $f.r1$subfield -text Yes ...
radiobutton $f.r2$subfield -text No ...
radiobutton $f.r3$subfield -text NA ...

# explicitly place the label and radiobuttons
grid $f.l$subfield -row $row -column 0 -sticky e
grid $f.r1$subfield -row $row -column 1 -sticky w
grid $f.r2$subfield -row $row -column 2 -sticky w
grid $f.r3$subfield -row $row -column 3 -sticky w
}

There are some final details to take care of. By default, rows and
columns don't grow and shrink so we need to give them "weight". In our
case we only want the right-most column and bottom-most row to grow and
shrink so it gets a weight of 1; all other rows and columns keep their
default weight of zero:

grid rowconfigure $f [incr row] -weight 1
grid columnconfigure $f 4 -weight 1

Hopefully you can take the above and make it work. I also hope it shows
that doing dynamic forms, even with nested fields, can be very easy if
you take the time to first draw out your layout and make a plan.

A couple other comments before I close. One, use "Yes", "No", "N/A"
instead of "YES", "NO", "NA". All caps makes the UI look like it's
screaming.

Second: I strongly recommend not using the fields array both for the
fields of a type and the subfields of fields. You'll get into trouble if
you ever have both a subfield and a field with the same name. Plus, it's
just darn confusing.

In other words, this:

foreach field $fields($type) {
foreach subfield $subfields($field) {

... is much easier to understand than what you have:

foreach field $fields($type) {
foreach FN $fields($field) {

Donald Arseneau

unread,
May 18, 2006, 11:34:47 PM5/18/06
to
krith...@yahoo.com writes:

> In the code I have I did the same way except I used frames instead of
> .prescrip.

Well, .prescrip is a frame, so I don't see how this is "except".

> I have may fields eg

I think what you have is correct, except maybe for the checkbuttons
under "cosmetics" maybe.

> for each of these fields. What I am i doing incorrect in my code that
> it is hanging?

The hanging was answered repeatedly already (mixing pack and grid) so
I thought you didn't have that problem anymore.


--
Donald Arseneau as...@triumf.ca

krith...@yahoo.com

unread,
May 19, 2006, 6:53:46 PM5/19/06
to
Hi
Thanks. the example was helpful though if I used it in mine the
packing did not happen correctly.

I did take the pack from my original code and only issue is it is more
than the width of the screen(lot of fields). So I am trying to add a
scrollbar. I am using
scrollbar .sbar -orient vertical -command {.t yview}
pack .sbar -side right -fill y

But no effect. Do I have to use with the frame. How do i add the
scrollbar for this?

Thanks
kc

Bryan Oakley

unread,
May 20, 2006, 12:26:22 AM5/20/06
to

Frames have no built-in scrolling ability; as you'll notice in the frame
man page there is no "yview" subcommand. There are a few ways to solve
the problem; I recommend you start here:

http://wiki.tcl.tk/9223

There are other options, but that might be your best bet.

If you have a form that has to be scrolled, your users likely won't be
very happy. You might want to consider other alternatives, like a
wizard-like interface or notebook tabs. Or choose widgets that take up
less space (such as a tk_optionMenu or combobox rather than three
radiobuttons)

krith...@yahoo.com

unread,
May 22, 2006, 3:32:51 PM5/22/06
to
Hello
Thanks. I tried to use tk_otionMenu but there is no difference. The
issue is the vertical alignmemnt which is no of fields. I was thinking
about moving to another form for each of the main filelds? Would that
be a desired option like

Field
Sub_field
Sub_field
Sub_field

NEXT(button) - to another form with the same as above

Let me know

How to use wizard like inteface or notebook tabs?

Thanks
kc

krith...@yahoo.com

unread,
May 22, 2006, 5:03:11 PM5/22/06
to
Hello
I read the wiki about scroll bar and these examples were complex for
me to understand. When I use the scroll bar command as above why does
notthing show in the widget? In the example you provided above how do
you add a scroll bar ?

Thanks
krithiga

Dan Smart

unread,
May 31, 2006, 11:54:19 PM5/31/06
to
<delurk>
On many dates and times, Bryan Oakley <oak...@bardo.clearlight.com> said:
[Lots of helpful stuff I have elided]

I'd just like to nominate Bryan as one of the most patient and helpful
people I've ever met. The amount of time he expends and patience he
demonstrates assisting people (some of whom have annoyed me to the
point of screaming by the time I've read half their post) is quite
amazing. The number of those people who thank him is equally amazing,
although somewhat more upsetting. It's something I almost wish I
aspired to, but I couldn't afford the alcohol bills, so I'll just have
to thank Bryan.

I should mention that Cameron Laird has been my long term hero in this
regard, and also performs stirling work in a number of communities.

While I single those two out, there are many others that collectively
make this one of the nicest newsgroups on the net; at least when I'm
not contributing.

Dan "The grumpy bastard will resume his normal programming tomorrow" Smart

Uwe Klein

unread,
Jun 1, 2006, 3:02:27 AM6/1/06
to
the "grumpy editor" your brother?
>
Should I take nominations for honorary mention in the TclUrl?

uwe

Wojciech Kocjan

unread,
Jun 1, 2006, 4:10:24 AM6/1/06
to
On Thu, 01 Jun 2006 05:54:19 +0200, Dan Smart <new...@dansmart.com> wrote:

> <delurk>
> On many dates and times, Bryan Oakley <oak...@bardo.clearlight.com> said:
> [Lots of helpful stuff I have elided]
>
> I'd just like to nominate Bryan as one of the most patient and helpful
> people I've ever met. The amount of time he expends and patience he
> demonstrates assisting people (some of whom have annoyed me to the point
> of screaming by the time I've read half their post) is quite amazing.
> The number of those people who thank him is equally amazing, although
> somewhat more upsetting. It's something I almost wish I aspired to, but
> I couldn't afford the alcohol bills, so I'll just have to thank Bryan.

> [..]

Yes, I agree that both Cameron and Bryan do a great job on this.

Do we have any stats on number of posts on c.l.t? I wonder what those are
:)

--
WK

suchenwi

unread,
Jun 1, 2006, 4:23:30 AM6/1/06
to

Wojciech Kocjan schrieb:

> Do we have any stats on number of posts on c.l.t? I wonder what those are

Sure: click "About this group" on the c.l.t front page.

Alan Anderson

unread,
Jun 1, 2006, 4:36:52 AM6/1/06
to
"suchenwi" <richard.suchenw...@siemens.com> wrote:

What "c.l.t front page"? I assume that c.l.t refers to the
comp.lang.tcl newsgroup, and I've never known a newsgroup to have a
front page. Is it a web site that you're talking about?

Uwe Klein

unread,
Jun 1, 2006, 4:32:39 AM6/1/06
to
last fortnight ( either Q or A ):

29 From: claird<XYZ>lairds.us (Cameron Laird)
25 From: "Gerald W. Lester" <Gerald.Lester<XYZ>cox.net>
24 From: David Gravereaux <davygrvy<XYZ>pobox.com>
22 From: Donald Arseneau <asnd<XYZ>triumf.ca>
21 From: Uwe Klein <uwe_klein_habertwedt<XYZ>t-online.de>
21 From: "maura.monville<XYZ>gmail.com" <maura.monville<XYZ>gmail.com>
19 From: Bruce Hartweg <bruce-news<XYZ>hartweg.us>
17 From: krithiga81<XYZ>yahoo.com
14 From: Bryan Oakley <oakley<XYZ>bardo.clearlight.com>
12 From: "Donal K. Fellows" <donal.k.fellows<XYZ>manchester.ac.uk>
11 From: Jeff Hobbs <jeffh<XYZ>activestate.com>
10 From: stephanearnold<XYZ>yahoo.fr
10 From: "suchenwi" <richard.suchenwirth-bauersachs<XYZ>siemens.com>
10 From: "Alex" <alexandre.ferrieux<XYZ>gmail.com>
9 From: mghembru<XYZ>harshrealm.uwaterloo.ca (MH)
9 From: Frank Goenninger DG1SBG <dont-email-me<XYZ>nomail.org>
9 From: "Robert Hicks" <sigzero<XYZ>gmail.com>
9 From: "Michael A. Cleverly" <michael<XYZ>cleverly.com>
8 From: Michael Schlenker <schlenk<XYZ>uni-oldenburg.de>
8 From: Ken Tilton <kentilton<XYZ>gmail.com>

uwe

Wojciech Kocjan

unread,
Jun 1, 2006, 5:12:49 AM6/1/06
to
On Thu, 01 Jun 2006 10:36:52 +0200, Alan Anderson <aran...@insightbb.com>
wrote:

Google groups. And it is there.

Unfortunately I don't know how to get stats on all 2006 for example (and
last month seems like a bit of a joke on the 1st :).

Anyway, Cameron is 3rd in "all time top posters". Impressive.

--
Wk

Michael Schlenker

unread,
Jun 1, 2006, 6:57:51 AM6/1/06
to
Wojciech Kocjan schrieb:
Try the netscan service from Microsoft:
http://netscan.research.microsoft.com/reportcard.aspx?tp=10&sd=5/30/2006&ng=comp.lang.tcl

Michael

Bryan Oakley

unread,
Jun 1, 2006, 8:58:56 AM6/1/06
to
Dan Smart wrote:
> <delurk>
> On many dates and times, Bryan Oakley <oak...@bardo.clearlight.com> said:
> [Lots of helpful stuff I have elided]
>

Thanks, Dan. Your check is in the mail :-)

Seriously, that was very kind of you to say. Thank you.

Cameron Laird

unread,
Jun 1, 2006, 11:29:50 AM6/1/06
to
In article <op.tagmj...@awk009-01.lab1.mpsc.mot.com>,
Wojciech Kocjan <wojciech...@k0cj4n.org> wrote:
.
.

.
>Unfortunately I don't know how to get stats on all 2006 for example (and
>last month seems like a bit of a joke on the 1st :).
>
>Anyway, Cameron is 3rd in "all time top posters". Impressive.
.
.
.
Those who want to play along from home can visit <URL:
http://groups.google.com/group/comp.lang.tcl/about >.

What this page *really* tells us is that one incarnation
of Cameron is third all-time, but soon to be passed by
tclguy's current address, who also accumulated a previous
total worth seventh overall. Note that long-time FAQ
maintainer Larry has two identities in the top five.

Kevin Walzer

unread,
Jun 1, 2006, 12:17:48 PM6/1/06
to
+1. Bryan and Cameron function as teachers in the best sense: they are
patient, and they provide suggestions and probing questions that often
let me solve my problems myself, as much as they provide outright
solutions. Their posts on c.l.t. could be collated into a useful
annotation/gloss on good Tcl/Tk programming practices. :-)

--
Kevin Walzer
Poetic Code
http://www.kevin-walzer.com

Jeff Hobbs

unread,
Jun 2, 2006, 1:24:36 AM6/2/06
to

All your post belong to me!

;)

Donal K. Fellows

unread,
Jun 2, 2006, 8:56:16 AM6/2/06
to
Dan Smart wrote:
> Dan "The grumpy bastard will resume his normal programming tomorrow" Smart

To help the grumpiness on it's way:
"Local Hero's" what? You s'eem to be s'uffering from Grocer's'
Apos'tophe.

Donal (posting this just to increase the number of messages this month
from this exact email adress... ;-)

Steve Peter

unread,
Jun 2, 2006, 12:16:48 PM6/2/06
to
"Donal K. Fellows" <donal.k...@manchester.ac.uk> writes:

> Dan Smart wrote:
>> Dan "The grumpy bastard will resume his normal programming tomorrow" Smart
>
> To help the grumpiness on it's way:
> "Local Hero's" what? You s'eem to be s'uffering from Grocer's'
> Apos'tophe.

Clearly, it's a Smart quote...

Donald Arseneau

unread,
Jun 2, 2006, 1:44:20 PM6/2/06
to
"Donal K. Fellows" <donal.k...@manchester.ac.uk> writes:

> Dan Smart wrote:
> > Dan "The grumpy bastard will resume his normal programming tomorrow" Smart
>
> To help the grumpiness on it's way:
> "Local Hero's" what?

"Local Hero is..." (Envelope please!)

--
Donald Arseneau as...@triumf.ca

Dan Smart

unread,
Jun 2, 2006, 11:13:42 PM6/2/06
to
On 2006-06-02 08:56:16 -0400, "Donal K. Fellows"
<donal.k...@manchester.ac.uk> said:

[fx: munch, munch, munch]

As usual, quantity not quality, you know you could have been a contender...

Bye...

Dan "Panda" Smart

lvi...@gmail.com

unread,
Jun 5, 2006, 9:05:59 AM6/5/06
to

According to Cameron Laird <cla...@lairds.us>:
:total worth seventh overall. Note that long-time FAQ

:maintainer Larry has two identities in the top five.


Ah - the hazards of changing work requirements, security people, etc. I've
had at least 3-4 ids during the many years that c.l.t. has been around.
Some of these appear high up, some don't.

I agree about the nominations of Cameron and Bryan, and while there
are others I could mention, as soon as I did, I would find yet another
coming to mind that I should mention, and I really do have work to get
done this morning ;-) ...
--
<URL: http://wiki.tcl.tk/ > Indescribable,uncontainable,all powerful,untameable
Even if explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.
<URL: mailto:lvi...@gmail.com > <URL: http://www.purl.org/NET/lvirden/ >

0 new messages