Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Tcl::Tk exit

by Sandy (Curate)
on May 24, 2017 at 19:03 UTC ( #1191134=perlquestion: print w/replies, xml ) Need Help??

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

Really silly question.

I am used to Perl/Tk, with sample code that looks like

use Tk; my $mw = MainWindow->new(-title=>"hello world"); $mw->Label(-text=>"hello")->pack(); $mw->Button(-text=>"Exit",-command=>sub{exit})->pack(); MainLoop;

Now I am updating (?) to Tcl::Tk (because Perl/Tk requires Quartz on my Mac)

use Tcl::Tk; my $int = new Tcl::Tk; my $mw = $int->mainwindow; $mw->Label( -text => "Hello World!" )->pack(); $mw->Button( -text => "Exit", -command => sub { exit } )->pack(); $int->MainLoop;

But when I exit, I get the following error message (and a segmentation fault)

perl5.18 quit unexpectedly while using the Tk plug-in.

I have tried combinations of $mw->exit(), but that also doesn't work.

Help.

Replies are listed 'Best First'.
Re: Tcl::Tk exit
by tybalt89 (Prior) on May 24, 2017 at 19:13 UTC

    I have neither Tcl::Tk nor a Mac, but my usual way to exit a Tk program is

    $mw->Button(-text=>"Exit",-command=>sub{$mw->destroy})->pack();

    this causes the MainLoop to return (so you could do some other cleanup before actually exiting).

      Never, ever thought of that. Thank you!
Re: Tcl::Tk exit ( Tcl::pTk )
by Anonymous Monk on May 24, 2017 at 23:36 UTC

    Now I am updating (?) to Tcl::Tk (because Perl/Tk requires Quartz on my Mac)

    Hi,

    Don't do that, thats busy work

    I can understand having to install other software being a pain, but avoid busywork

    Install Tcl::pTk and use Tcl::pTk; and you're mostly done

      Why I have to move from Perl/Tk

      On MAC, results look crappy using Quartz.

      Users of my tool are not computer savvy, and prefer a zip, unzip, ready to go tool

      So, are you saying that Tcl::pTk is more similar to Perl/Tk than Tcl::Tk?

      I am still assessing options

      Thanks

        G'day Sandy,

        "On MAC, results look crappy using Quartz."

        In general, I don't disagree with this at all.

        Having said that, if your only issue is one of look and feel, then that's what I'd target for change (rather than rewriting all of your Tk applications in a different flavour of Tk).

        Unfortunately, while I can agree with "look crappy" in general, that doesn't really provide much in the way of concrete information. Here's a couple of suggestions.

        The default fonts (Times, Helvetica and Courier) are intended to work on any platform; however, that's where it ends — there's no promise of how they'll look on any particular platform. Consider changing these to ones you prefer. I don't normally use a serif font in Tk applications; for sans-serif and monospace my personal preferences would possibly be Verdana and Menlo. Take a look Tk::Font.

        I personally find the default look and feel to be rather chunky; in particular, the 2px borders around buttons, scrollbars and other widgets. Simply changing those to 1px may make a big difference. See Tk::options for the standard options; follow links from the Tk distribution page for widget-specific options.

        You can use the option database (Tk::option) to make those changes globally, for all of your applications, as a one-off task; you don't need to go through every application and change every instance of -font, -borderwidth, and so on.

        — Ken

        > On MAC, results look crappy using Quartz.

        Maybe you need to add the XFT=1 option to Makefile.PL?

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

        On MAC, results look crappy using Quartz.

        They should look familiarly like Tk

        Users of my tool are not computer savvy, and prefer a zip, unzip, ready to go tool

        Not sure what that has to do with your choice of "Tk" flavor, since you're going to be distributing the zip for your users, just provide everything required, as cavapackager/citrusperl/PAR can help you provie

        So, are you saying that Tcl::pTk is more similar to Perl/Tk than Tcl::Tk? I am still assessing options

        Hehehe, Tcl::pTk is a "Tk.pm" interface to "Tcl::Tk" that is you change nothing in your Tk.pm code, just add one line (maybe two), and you get "Tcl::Tk" looks

Re: Tcl::Tk exit
by chrstphrchvz (Scribe) on May 09, 2019 at 22:14 UTC

    I rediscovered this issue in Tcl::pTk; see RT #128654.

    The simple explanation is that Perl/Tk redefines exit (see Mastering Perl/Tk 1.4.1 "exit Versus destroy"), while Tcl::Tk and Tcl::pTk do not. I do not know the details of why using exit in Tcl::(p)Tk causes errors; maybe Perl/Tk's exit implementation offers more insight.

    The working alternative is to use destroy, and as tybalt89's answer points out, it allows code appearing after MainLoop and any other cleanup code to run, unlike exit.

    Even though -command => \&exit and -command => sub { exit } are documented and common idioms in Perl/Tk, I would not be surprised if Tcl::Tk chooses to not support these, given the available alternative; and even if supporting these is desirable for Tcl::pTk, I'm not sure whether that can or will ever get implemented. I suggest following the RT ticket in case of any updates.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1191134]
Approved by sweetblood
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2021-11-27 20:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?