Problem getting status of Checkbutton widget 
Author Message
 Problem getting status of Checkbutton widget

I have a large set of checkbutton widgets, none of which have the -variable
option set. According to Perl/Tk documentation, the default variable name
should be the last part of the widget name in the widget path, but I cannot
seem to get this working. Everything is fine when I use -variable, but I
really need to get this working using the default variable value because
the widgets are being dynamically generated and I don't want to make up
variable names for each widget.

Can anyone send me a quick code snippet of how to access the default
variable holding the checkbutton status?

Thanks!



Mon, 23 Jun 2003 05:34:38 GMT  
 Problem getting status of Checkbutton widget
Just to add to my own post...

The reason why I can't use a hardcoded variable for "-variable" in the
checkbutton widget is because I don't know what the names will be until
runtime. The checkbutton widgets are being created dynamically. So I need
to understand how to access the default variable used by "-variable".

Please help if you can.

Thanks!



Mon, 23 Jun 2003 06:19:22 GMT  
 Problem getting status of Checkbutton widget

Quote:
> I have a large set of checkbutton widgets, none of which have the -variable
> option set. According to Perl/Tk documentation, the default variable name
> should be the last part of the widget name in the widget path, but I cannot
> seem to get this working.

The documentation I am reading says something different:

        Defaults to \$widget->{'Value'} member of the widget's hash.

Quote:
>                            Everything is fine when I use -variable, but I
> really need to get this working using the default variable value because
> the widgets are being dynamically generated and I don't want to make up
> variable names for each widget.

> Can anyone send me a quick code snippet of how to access the default
> variable holding the checkbutton status?

        use strict;
        use Tk;
        my $mw = tkinit;

        my $I = 0;
        $cb[$I] = $mw->Checkbutton(-text => $I++)->pack;
        $cb[$I] = $mw->Checkbutton(-text => $I++)->pack;
        $cb[$I] = $mw->Checkbutton(-text => $I++)->pack;
        $cb[$I] = $mw->Checkbutton(-text => $I++)->pack;
        $cb[$I] = $mw->Checkbutton(-text => $I++)->pack;
        $cb[$I] = $mw->Checkbutton(-text => $I++)->pack;
        $mw->Button(-text => 'Print Values', -command => sub{

                            print $I, ': ', $cb[$I]->{'Value'}, "\n";
                        }
                }
        )->pack;
        MainLoop;

--
Marc Dashevsky  (remove "_" from address to reply by e-mail)



Mon, 23 Jun 2003 09:35:14 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. compile error on widget using Checkbutton

2. compile error on widget using Checkbutton

3. Problems getting values back for Entry widgets

4. Label Widget Used for Status Bar

5. Looking for Text-based Status widget

6. Trouble getting a status back from SMTP

7. Getting status of radio buttons and check boxes without binding variables

8. menu checkbutton and radiobutton problem

9. TK::checkButton problem

10. Weird problem with checkbutton and menubuttons

11. Help - Changing from status line to status box

12. Getting size of Tk Text widget

 

 
Powered by phpBB® Forum Software