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 ); }

In reply to Perl/Tk getOpenFile() error in a 2nd toplevel window by moonkey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.