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

I am trying to write a GUI for playing Goe, which is a board game polular in east Asia. As I want the program be able to run on all OS platforms(at least on Linux and Windows) without modification, Perl/Tk seems to be the right candidate.

I encoutered a problem with getOpenFile( ), and I included reduced sample code at the end of this message.

getOpenFile() works fine for the 1st window, but if I clone a window, getOpenFile() will generate the following error:

Tk::Error: image "image1" doesn't exist at /usr/lib/perl5/site_perl/i386-linux/Tk/FBox.pm line 91.

(the above is the 1st line of the errors) which I tried to eliminate but didn't succeed.

I am running the code on Slackware Linux 7.1, Perl 5.6.0, Tk800.024.

Please try the following code and I am desperately in need of all you monks' wisdoms.

(If my English is not accurate, please forgive your eastern counterpart :-)

#!/usr/bin/perl -w use strict; use Tk; my $FileName; NewWindow( ); MainLoop; sub NewWindow { my $mw = MainWindow->new; $FileName = ""; $mw->Button( -text => "New Window", -width => 16, -command => \&NewWindow )-> grid( -row => 0, -column => 0 ); $mw->Button( -text => "Select File", -width => 16, -command => [ \&ChooseAFile, $mw ] )-> grid( -row => 0, -column => 1 ); $mw->Button( -text => "Exit", -width => 16, -command => sub { $mw->destroy; } )-> grid( -row => 0, -column => 2 ); $mw->Label( -textvariable => \$FileName, -width => 50, -relief => "flat" )-> grid( -row => 1, -column => 0, -columnspan => 3 ); } sub ChooseAFile { my $mw = shift; my @types = ( [ "All files ", '*' ] ); $FileName = $mw->getOpenFile( -filetypes => \@types ); }

Replies are listed 'Best First'.
Re: Perl/Tk getOpenFile( ) error in the other toplevel window
by svad (Pilgrim) on Apr 26, 2002 at 16:21 UTC
    I assure you that your code works perfectly well on my system (Win2k+perl-5.6.1+Tk-800.022).
    It did not reported any errors.
    The main reason of this difference is, in my opinion, that on Win32 getOpenFile calls native to Win32 standard dialogbox, whereas on Linux Perl+Tk constructs that box by itself and, probably, does not supports your case (by mistake).
Re: Perl/Tk getOpenFile( ) error in the other toplevel window
by BlueBlazerRegular (Friar) on Apr 26, 2002 at 16:13 UTC
    moonkey,

    I'm running on Win NT and it works fine there.

    Does the reduced code you included fail in the same way as the full-size program?

Re: Perl/Tk getOpenFile( ) error in the other toplevel window
by moonkey (Initiate) on Apr 27, 2002 at 07:55 UTC

    this morning I tried the code on a Windows2000, it works perfect.

    yes, the reduced code fail the very same way as the full-sized program. the only minor difference is that in the error message it will be "image2" instead of "image1".

    it is interesting that if I click the "New Window" button and then click "Select File" button in the 2nd window first, it works(!) for the 2nd window, but will fail for the original window this time. No matter if you destroy the successful window or not.

    this phenomenon seems to suggest that the FBox object definition has difficulty in multi-entry.

    I tried to read the source of FBox.pm. however, I cannot see a easy fix. Or should I contact the Perl/Tk mantainers?

    Probably Perl/Tk developers are active on perlmonks.org. Then I shall not need to pray in another temple:-)

Re: Perl/Tk getOpenFile( ) error in the other toplevel window
by svad (Pilgrim) on Apr 27, 2002 at 09:25 UTC
    write to ptk list at ptk@lists.Stanford.EDU and they will help you for sure.
    I almost know how to help you with fixing, (it seems to me I understood the core of an error) but my Linux box is at home and my spare time is absent at all...
Re: Perl/Tk getOpenFile( ) error in the other toplevel window
by aplonis (Pilgrim) on Jan 15, 2005 at 00:01 UTC

    I reproduce your problem on NetBSD 1.6.2 with Perl 5.8. It has to do with the "my" statement for "$mw" being inside the def for the sub.

    If you remove the "my" from inside the sub and instead declare "$mw" outside the sub via either a "my $mw;" or else a "use vars qw( $mw );" then the problem goes away.

Re: Perl/Tk getOpenFile( ) error in the other toplevel window
by vkonovalov (Monk) on Apr 26, 2002 at 16:30 UTC
    I wonder who did '--' to the quite good program example with a high quality of code and with a good question. I ceartainly ++ it!
    Sorry for offtopic

    Originally posted as a Categorized Answer.

Re: Perl/Tk getOpenFile( ) error in the other toplevel window
by vkonovalov (Monk) on Apr 26, 2002 at 16:30 UTC
    I wonder who did '--' to the quite good program example with a high quality of code and with a good question. I ceartainly ++ it!
    Sorry for offtopic

    Originally posted as a Categorized Answer.