Unkown Widget 
Author Message
 Unkown Widget

greetings,

  maybe this group can be of assitance. I am just learning perl/tk and I
am building a sample script that perl.com had so I can get a better
understanding.

here is the the code that I have:

#!/usr/bin/perl -w

use English;
require Tk;
use Tk;

my $Version="1.0";

my $main=MainWindow->new();
$main->minsize( qw(250 250));
$main->title (" Contractors Pay Calculator");
$main->configure (-background=>'red');

MainLoop();
my $menu_bar=$main->Frame(-relief=>'groove',
        -borderwidth=>3,
        -background=>'purple',
        )->pack(-side=>'top',-fill=>'x');

my $file_mb=$menu_bar->Menubutton(-text=>'File',
        -background=>'purple',
        -activebackground=>'cyan',
        -foreground=>'white',
        )->pack(-side=>'left');

When I try to run it I don't get the menu bar. And when I close the
window this is the error that I get:

MainWindow=HASH(0x401ae044) is not a widget at ./window.pl line 15

I hope someone can assist.

Al Smith
Systems Engineer
Thomas Jefferson University Hospital



Fri, 06 Sep 2002 03:00:00 GMT  
 Unkown Widget
Al,

You need to create all of your widgets before calling MainLoop.  When you
call MainLoop, Tk takes control to process all of the GUI events (drawing,
keyboard, mouse, etc.).  MainLoop does not return until you explicitly exit
in response to an event (using a binding) or if you close your main window.

I'm not positive here, but I think it's pretty safe to say that all of the
widgets are destoryed by the time MainLoop returns.  That being the case,
your code after MainLoop will fail since $main will have been destroyed
already.  If you move MainLoop to the end of your code, all should be good.

Also, since "use Module LIST" is equivalent to "BEGIN { require Module;
import Module LIST; }", you can remove "require Tk;".  "use Tk;" is already
"require"ing the module.

Kevin



Fri, 06 Sep 2002 03:00:00 GMT  
 Unkown Widget

Quote:
> When I try to run it I don't get the menu bar. And when I close the
> window this is the error that I get:

> MainWindow=HASH(0x401ae044) is not a widget at ./window.pl line 15

Well, you had defined the menu after $main had been closed.
More than simply fixing that, though, I recommend that you
use the relatively new concept of menubar rather than the
deprecated Menubutton.  The following code works for me:

#!/usr/bin/perl -w

use English;
require Tk;
use Tk;

my $Version="1.0";

my $main=MainWindow->new();
$main->minsize( qw(250 250));
$main->title (" Contractors Pay Calculator");
$main->configure (-background=>'red');

my $menu_bar = $main->Menu(-type => 'menubar');
$main->configure(-menu => $menu_bar);
my $file_mb=$menu_bar->cascade(-label => '~File');
$file_mb->command(-label => '~New');
$file_mb->command(-label => '~Open');
$file_mb->separator;
$file_mb->command(-label => '~Quit', -command => sub {exit 0;});

MainLoop();

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



Sat, 07 Sep 2002 03:00:00 GMT  
 Unkown Widget
I would like to thank everyone for their help on this matter. Every one
pointed out the same fact that I put more code after the MainLoop(); .
After looking at it again more closely I found it.

Thanks for all your help.

-Al



Sat, 07 Sep 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Unkown Error

2. Composite Widget with NO widgets - Possible?

3. Can Tk Widget and Xt Widget work together?

4. Is there a Tree widget in perlTk that resembles the Tree widget in Tk

5. Graph widgets in general (was Re: BLT Graph Widget)

6. pTk 8.4.24 widget patch #1 - widget demo and friends bug fixes/modernizations

7. how to get child widget from the top level widget ?

8. how to bind alt-f to find widget in Text widget ?

9. Newbie -> $widget->send $widget->Receive ; eventGenerate

10. ActiveX container widget? Also, writing widgets in C?

11. tkperl5a5 - what happend to the text widget?

12. Tkperl5a5 Widget: FileChooser.pm

 

 
Powered by phpBB® Forum Software