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

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

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

getOpenFile() works fine for the 1st window in which you clicked the "Select File" Button. But if you click the button in a 2nd 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 for i386, Perl 5.6.0, Tk800.024.

BTW, the sample code runs perfect on Windows 2000, running ActivePerl.

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; $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 $myWidget = shift; my @types = ( [ "All files ", '*' ] ); $FileName = $myWidget->getOpenFile( -filetypes => \@types ); }

Replies are listed 'Best First'.
Re: Perl/Tk getOpenFile() error in a 2nd toplevel window
by svad (Pilgrim) on Apr 27, 2002 at 17:35 UTC
    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).

    why I have strange de-javu feeling? :)
    Warmest wishes,
    Vadim.