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

I write a Tk program and it works fine. However, a command prompt window always opens in the background as the gui program opens. Any way I can get rid of it? Thanks to the saints!

Retitled by davido.

  • Comment on Tk on Win32 - how to avoid background console window

Replies are listed 'Best First'.
Re: Tk on Win32 - how to avoid background console window
by Errto (Vicar) on Jan 18, 2005 at 02:00 UTC
    I assume you're on Windows (if I'm right, please update your node title to reflect this). In that case, you can use exetype to create a "guiperl" version of the perl runtime that will not open a console window.

      I can legitimately claim to have written the first version of exetype. In REXX, for IBM under OS/2, circa 1988!


      Examine what is said, not who speaks.
      Silence betokens consent.
      Love the truth but pardon error.
      Great! Thanks a lot.
      Yes it is on Windows. It looks like for exectype to work you already need a .exe. I only have my .pl thanks
Re: Tk on Win32 - how to avoid background console window
by strat (Canon) on Jan 18, 2005 at 08:03 UTC

    if you use activestate perl under windows, you could run it with the wperl.exe found in your perl\bin directory

    For perl/tk-scripts, I usually use the file ending of .ptk, and associate this ending with wperl. so, for development, I can execute it with perl script.ptk and have a doswindow, and for the final version, I just execute it script.ptk and get rid of this window.

    You can associate .ptk with wperl.exe the following way:

    assoc .ptk=PerlTk ftype PerlTk=c:\perl\bin\wperl.exe "%1" %*

    (if you want some fun, read the output of ftype /? under WinNT/2k/XP/2003... perl really seems to be supported by M$)

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

      Realy cool. Thank you.
Re: Tk on Win32 - how to avoid background console window
by mawe (Hermit) on Jan 18, 2005 at 05:16 UTC
    Hi!

    I don't work with Windows and I'm not a saint, but I do have a Perl Cookbook :-) The solution there is: Start your program through another Perl script. Here is the snippet:

    #!/usr/bin/perl -w # loader - starts Perl scripts without the annoying DOS window use strict; use Win32; use Win32::Process; # Create the process object. Win32::Process::Create($Win32::Process::Create::ProcessObj, 'C:/perl5/bin/perl.exe', # Whereabouts of Perl 'perl realprogram', # 0, # Don't inherit. DETACHED_PROCESS, # ".") or # current dir. die print_error(); sub print_error() { return Win32::FormatMessage( Win32::GetLastError() ); }
    Regards, mawe
      Sounds great. Thank you very much.
      You don't work on Windows and you are not a saint, but you sure gave me the right answer. Thank you
Re: Tk on Win32 - how to avoid background console window
by teabag (Pilgrim) on Jan 18, 2005 at 10:14 UTC
    An other option would be to use PAR
    with pp, perl packager. Just add the --gui switch to tell pp that it's a gui program:

    # Pack 'foo.pl' into a console-less 'out.exe' with icon (Win32 only) pp --gui --icon foo.ico -o out.exe foo.pl


    teabag
    Blessed is the end user who expects nothing, for he/she will not be disappointed.
Re: Tk on Win32 - how to avoid background console window
by jeepj (Scribe) on Mar 21, 2008 at 09:57 UTC

    Having to deal recently with the same king of problem, and with an older version of ActiveState which didn't include wperl.exe, I found yet another way to do it. Hope this could help someone.

    BEGIN { if ($^O eq 'MSWin32') { require Win32::Console; Win32::Console::Free( ); } }

    The DOS window is showing up at the start of the script, and disappear instantly.