Sanko Robinson > FLTK-0.532009 > FLTK::Cookbook::MenuBar::Toggle


Annotate this POD


View/Report Bugs


FLTK::Cookbook::MenuBar::Toggle - Shows how to toggle menu items at run time

Description ^

Demonstrates how to toggle a menu item procedurally. Click on Options to view the toggled menu items.

The Code ^

    use strict;
    use warnings;
    use FLTK;
    my $win = FLTK::Window->new(720, 486);
    my $menubar = FLTK::MenuBar->new(0, 0, 720, 25);
    for my $mnu (qw[One Two Three]) {

    # Test the state changes -- turn 'One' off, others on
    warn 'FAILED[1]' if (SetMenuItemState($menubar, "Options/One",   0) < 0);
    warn 'FAILED[2]' if (SetMenuItemState($menubar, "Options/Two",   1) < 0);
    warn 'FAILED[3]' if (SetMenuItemState($menubar, "Options/Three", 1) < 0);
    exit FLTK::run();

    sub SetMenuItemState {
        my ($self, $name, $state) = @_;
        my $m = $self->find($name);
        return -1 if !$m;
        return $m->set() if $state;
        return 0;

Awknowlegements ^

Code based on the work of Greg Ercolano

Author ^

Sanko Robinson <> -

License and Legal ^

Copyright (C) 2008-2009 by Sanko Robinson <>

This program is free software; you can redistribute it and/or modify it under the terms of The Artistic License 2.0. See the LICENSE file included with this distribution or For clarification, see

When separated from the distribution, all original POD documentation is covered by the Creative Commons Attribution-Share Alike 3.0 License. See For clarification, see

syntax highlighting: