eserte / perl-tk

the perl module Tk
https://metacpan.org/release/Tk
Other
44 stars 31 forks source link

Fix typos #73

Closed mohawk2 closed 3 years ago

mohawk2 commented 3 years ago

Found these while trying to figure out why my local use of -textvariable wasn't working, thought I'd GitHub-search the repo.

That was in fact because I passed the value of the variable, not a reference to it. Do you think the Perl use of that should croak if a non-scalar-ref value is given?

Also, Perl/Tk doesn't have an equivalent of tkinter's "simpledialog". This is only a few lines, but it took me a couple of hours to figure out. Should this be either in docs, or a small provided class? If so, please say so and I'll PR it.

sub simpleDialog {
  my ($mw, $title) = @_;
  require Tk::DialogBox;
  require Tk::Entry;
  my $dialog = $mw->DialogBox(-title => $title, -default_button => 'OK', -buttons => [qw/OK Cancel/]);
  my $entry = $dialog->add('Entry')->pack;
  $dialog->configure(-focus => $entry);
  my $ans = $dialog->Show;
  my $text = $entry->get;
  $dialog->destroy;
  $ans ne 'OK' ? undef : $text;
}
mohawk2 commented 3 years ago

Thanks for merge! Got any thoughts on the questions asked above? :-)

eserte commented 3 years ago

ad -textvariable: I was curious whether it's possible to make use of a non-reference -textvariable. A provided non-ref value is simply displayed in the entry and the value may be later retrieved using $entry->cget('-textvariable'). Quite obscure, but I can imagine that some users are using it this way... nevertheless I tried to restrict the accepted type by using TK_OPTION_SCALARVAR instead of TK_OPTION_OBJ in tkEntry.c, but this did not work --- it seems that TK_OPTION_SCALARVAR deliberately accepts non-ref scalars, and that a new config option TK_OPTION_SCALARREFVARor so is needed...

ad simpleDialog: a possible approach would be to create a normal CPAN module for this. Later we can decide to "absorb" this module into Tk core (this already happened in the past, AFAIR Tk::PNG and Tk::JPEG used to be separate modules).