use warnings; use strict; { package OptionsTest; use Cwd; use Tk qw(MainLoop); require Tk::ROText; sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = bless { @_ }, $class; my $mw = MainWindow->new(); $self->{MW} = $mw; $self->MakeWidgets; $mw->configure(-title => "Options Test"); my $menu = $mw->Menu(-type => 'menubar'); $mw->configure(-menu => $menu); $self->BuildMenu($menu); $self->{SETTINGS} = { thing1 => 7 }; $self->{thing2} = 3; MainLoop(); } sub BuildMenu { my ($self, $menu) = @_; $menu->Cascade( -label => 'Options', -tearoff => 0, -menuitems => [ ['checkbutton', 'thing1', -variable => \$self->{SETTINGS}->{thing1}, -command => sub { $self->AdjustConsole(); }], ['checkbutton', 'thing2', -variable => \$self->{thing2}, -command => sub { $self->AdjustConsole(); }], ] ); } sub MakeWidgets { my ($self) = @_; my $frm = $self->{MW}->Frame()->pack(qw(-side top -fill both -expand 0)); $self->{CONSOLE} = $frm->Scrolled('ROText', -font => "{Courier New} 12 bold", -background => 'DarkBlue', -foreground => 'OldLace', -scrollbars => 'se', -wrap => 'none', -height => 10, -width => 60, -tabs => ['2'], )->pack(-expand => 1, -fill => 'both', -anchor => 'n' ); tie *STDOUT, 'Tk::Text', $self->{CONSOLE}; # Send STDOUT to console tie *STDERR, 'Tk::Text', $self->{CONSOLE}; # Send STDERR to console } sub AdjustConsole { my ($self) = @_; printf( "thing1: %s %s thing2: %s %s\n", \$self->{SETTINGS}->{thing1}, $self->{SETTINGS}->{thing1}, \$self->{thing2}, $self->{thing2}); } } OptionsTest->new();