Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Using Tk inside a Perl exe

by marto (Cardinal)
on Nov 16, 2018 at 11:02 UTC ( [id://1225903]=note: print w/replies, xml ) Need Help??


in reply to Using Tk inside a Perl exe

Post a SSCCE and show how you're calling pp to package your application.

Replies are listed 'Best First'.
Re^2: Using Tk inside a Perl exe
by Garden Dwarf (Beadle) on Nov 16, 2018 at 11:55 UTC
    No problem, here you go:
    END{ #!/bin/perl use Tk; use strict; use warnings; use Data::Dumper; print "The fils is located here: ".Tk::findINC('icon.png')."\n"; exit 0; }

    ... and the compilation instructions (icon.png is in the same directory as the Perl code):

    pp -a "icon.png;resources/icon.png" -o example.exe example.pl

    After executing the exe, I have the following message:

    Can't call method "crc32String" without a package or object reference +at (...)/strawberry-perl-5.14.4.1-64bit-portable/perl/vendor/lib/PAR/ +Heavy.pm line 146. END failed--call queue aborted at -e line 965.

      Thanks. Looking at findINC it'll search @INC for a file. If icon.png is in the same directory as example.pl, example.pl fails to execute with the same error. I'm not a Tk expert, there are many nodes here from people with much more experience (Super Search, DuckDuckGo etc..)

      However, you're specifically adding this file to resources/icon.png, either altering your code to Tk::findINC('resources/icon.png') and packaging the way you did will work, e.g.

      The fils is located here: /tmp/par-6d6172746f/cache-535ec6de1b4efb148a +c99123aadeb8c4f902fa64/inc/resources/icon.png

      Or just don't package that way:

      marto@Shemp:~/tkpp$ ls icon.png tk.pl marto@Shemp:~/tkpp$ pp -a "icon.png;icon.png" -o tk tk.pl marto@Shemp:~/tkpp$ ./tk The fils is located here: /tmp/par-6d6172746f/cache-df7f1b303bbe076aaf +1a97c9630e6d50e56371c6/inc/icon.png

      I've posted an example in the past showing how to determine if the code is being run via a script of a PAR packaged executable, let me know if you can't find this, should you go looking.

      Lastly, I don't know what you want to do with the png file, perhaps there's a better more portable way to achieve that.

        Thanks. Looking at findINC it'll search @INC for a file. If icon.png is in the same directory as example.pl, example.pl fails to execute with the same error. I'm not a Tk expert [...]

        Modern perls (since v5.26.0) no longer include '.' in @INC, so findINC no longer searches there.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        Using the path resources/icon.png instead of just icon.png is working. Thanks a lot! :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1225903]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 12:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found