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.
Re: Tcl::Tk exit
by tybalt89 (Monsignor) 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).
| [reply] [d/l] |
|
Never, ever thought of that. Thank you!
| [reply] |
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
| [reply] [d/l] |
|
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
| [reply] |
|
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.
| [reply] [d/l] [select] |
|
|
| [reply] [d/l] [select] |
|
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
| [reply] |
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.
| [reply] |
|
|