Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Perl/TK: enabling a disable menu item

by chimni (Pilgrim)
on Jul 30, 2003 at 04:26 UTC ( [id://279075]=perlquestion: print w/replies, xml ) Need Help??

chimni has asked for the wisdom of the Perl Monks concerning the following question:

Hi i have this menu and want to enable the disabled button later on. How do i go about t his.
my $sv_menu = $menubar->Menubutton( -text => "Sv", -activebackground => 'blue', -activeforeground => 'white', -tearoff => 0, -menuitems => [ [ Button => '~Conf', -command => \&hello, -accelerator => '<Ctrl-c>' ], [ Button => "~Utility", -command => \&ello , -accelerator => '<Ctrl-u>' ], ["separator" => " "], ] )->pack(-side => 'left');

How do i go about enabling the edit menu in a subroutine in which i have checked that a file has been selected

As always ,ur input is appreciated
Regards,
chimni

edited: Wed Jul 30 13:58:20 2003 by jeffa - reformatted whitespace in code, removed opening pre tag

Replies are listed 'Best First'.
Re: Perl/TK: enabling a disable menu item
by busunsl (Vicar) on Jul 30, 2003 at 06:29 UTC
    Since there is no 'edit' button in your source, I assume you want to add it to the menu. To add a menuitem use the AddItems method of the menubutton like this:
    $sv_menu->AddItems([command => 'Edit', -command => \&edit]);
Re: Perl/TK: enabling a disable menu item
by bobn (Chaplain) on Jul 30, 2003 at 07:05 UTC

    If the edit menu (which appears nowhere in your sample code, so we have to guess) is a separate Menubutton object ( as in my $sv_menu2 = $menubar->Menubutton(yada yada), then you enable it with $sv_menu2->configure(-state => 'normal') and disable it with $sv_menu2->configure(-state => 'disable')

    --Bob Niederman, http://bob-n.com
Re: Perl/TK: enabling a disable menu item
by chimni (Pilgrim) on Jul 30, 2003 at 07:10 UTC
    sorry posted the wrong menu code.
    Please refer to the following code.
    
    my $file_menu = $menubar->Menubutton(-text => "File", -activebackground => 'blue', -activeforeground => 'white', -tearoff => 0, -menuitems => [ [Button => '~Sele +ct', -command => \&select_file , -accelerator => '<Ctrl-s>'], [Button => "~Edit +",-state => 'disabled', -command => \&edit_file , -accelerator => '<Ctrl-e>' ], [Button => '~Gene +rate XML', -state => 'disabled',-command => \&gen_xml , -accel erator => '<Ctrl-x>'], ["separator" => " + "], [Button => "Exit +", -command => sub {exit 0;} , -accelerator => 'ESC'] ])->pack(-side => + 'left');

      After staggering through Mastering Perl/Tk, I come up with this, which seems to work:

      my $fm = $menubar->entrycget('File', -menu); # *after* creating the File Menubutton in the $menubar sub select_file { $fm->entryconfigure('Edit', -state=>'normal') }
      --Bob Niederman, http://bob-n.com
Re: Perl/TK: enabling a disable menu item
by chimni (Pilgrim) on Jul 31, 2003 at 04:22 UTC

    Hi people
    i ran the following code
    my $fm = $menubar->entrycget('File', -menu); sub select_file { $fm->entryconfigure('Edit', - state=>'normal') }
    It gives me the error that entrycget.pm cannot be found in @INC.(Can't locate Tk/Frame/entrycget.pm)
    I searched for this module on google and on cpan. I cannot find it anywhere ???
    Could anyone lead me to it
    thanks
    rajdeep

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://279075]
Approved by martymart
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-20 01:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found