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

A coworker tried to run a Perl/Tk program I worte under Win7 with Strawberry Perl 5.16.3

He got the error:

C:\Users\rowilson\Projects\Tools>perl UpdateP4SM.pl Tk::Error: bad file type "ARRAY(0x7ad618)", should be "typeName {exten +sion ?exte nsions ...?} ?{macType ?macTypes ...?}?" at c:/Perl/perl/site/lib/Tk.p +m line 338

The filetype specification is almost copy/paste from Tk:getOpenFile and it worked on my Linux system.

Also, I changed the program to use Tk::FBox, instead, but while it works, when the program starts, a partially functioning (and useless) FBox is opened. Ok and Cancel have no affect. But, when the button on the main window is clicked, the useless one disappears and a properly functioning one appears.

My code (with the business logic removed) is:

#!perl -w use strict; use Tk; use Tk::Label; use Tk::Text; use Tk::Button; use Tk::FBox; my $Type_P4SM = [ [ 'P4SM', '.p4sm' ] ]; my $File_P4SM; my $mw=MainWindow->new(-title=>'UpdateP4SM'); my $w_Lab_Step1 = $mw -> Label ( -justify=>'left', -relief=>'flat', -t +ext=>'Copy/Paste Commit Log from P4 to here:' ) -> grid(-row=>0, -col +umnspan=>3, -column=>0, -sticky=>'nw'); my $w_Text_Commit = $mw -> Scrolled ( 'Text', -state=>'normal', -relie +f=>'sunken', -scrollbars=>'se', -wrap=>'none' ) -> grid(-row=>1, -col +umnspan=>3, -column=>0, -sticky=>'nw'); my $w_Lab_Step2 = $mw -> Label ( -justify=>'left', -relief=>'flat', -t +ext=>'P4SM file to update:' ) -> grid(-row=>2, -column=>0, -sticky=>' +nw'); my $w_Button_P4SM = $mw -> Button ( -overrelief=>'raised', -command=>\ +&Show_Open_P4SM, -width=>20, -state=>'normal', -relief=>'raised', -co +mpound=>'none', -textvariable=>\$File_P4SM ) -> grid(-row=>2, -column +=>1, -sticky=>'nwe'); my $w_FBox_P4SM = $w_Button_P4SM -> FBox ( -title=>'Select P4SM to Upd +ate', -filetypes=>$Type_P4SM, -type=>'open' ); my $w_Button_Update = $mw -> Button ( -overrelief=>'raised', -command= +>\&updateP4SM, -state=>'normal', -relief=>'raised', -text=>'Update', +-compound=>'none' ) -> grid(-row=>3, -column=>1, -sticky=>'new'); my $w_Button_Quit = $mw -> Button ( -overrelief=>'raised', -command=>\ +&Quit, -state=>'normal', -relief=>'raised', -text=>'Quit', -compound= +>'none' ) -> grid(-row=>4, -column=>2, -sticky=>'ne'); MainLoop; sub Show_Open_P4SM { # $File_P4SM = $mw->getOpenFile( -title=>'Select P4SM to Update', +-filetypes=>$Type_P4SM ); $File_P4SM = $w_FBox_P4SM->Show(); } sub updateP4SM { print "Updating $File_P4SM....\n"; } sub Quit { Tk::exit; }

Replies are listed 'Best First'.
Re: Tk strangeness
by kevbot (Vicar) on May 10, 2014 at 04:06 UTC

    Try adding a second file type specification and see if the error goes away on Win32.

    Quite a while back (I'm unsure of which version of Tk was installed), I recall getting an error in a similar circumstance. I just found a comment in my old code that said that I needed to add a second file type for the code to run properly in Win32. I also seem to recall that the code in question ran fine on my Mac (and likely also ran fine on linux). So, try something like this:

    my $Type_P4SM = [ [ 'P4SM', '.p4sm' ], [ 'All Files', '*.*'] ];
    Please report back if this fixes your problem, as it may inspire me to file a bug report. I just took a quick look through the list of active bugs for Tk and did not see any bugs that looked similar to this one.
      Yes, thanks. That worked. Is rare I create a tool with a GUI. also, the app that uses the p4sm file only accepts the extension .p4sm
Re: Tk strangeness
by kevbot (Vicar) on May 13, 2014 at 03:51 UTC