Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Perl Tk, how to get File Browser, capture output to a Log file and format my checkboxes

by tybalt89 (Monsignor)
on Mar 22, 2022 at 12:22 UTC ( [id://11142279]=note: print w/replies, xml ) Need Help??


in reply to Perl Tk, how to get File Browser, capture output to a Log file and format my checkboxes

See the NOTE comments for possible solutions to some of your n) issues.

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11142273 use warnings; use Tk; my $additionalcheckbutton = 0; my @checkbuttonlabels = split /\n/, <<END; one two very long text entry for test purposes three for more info align problem four extra check END my @values = (0) x @checkbuttonlabels; my $wantspecial = 0; my $notes; my $mw = MainWindow->new; $mw->geometry('+700+400'); $mw->Button(-text => 'Exit', -command => sub{$mw->destroy}, )->pack(-side => 'bottom', -fill => 'x'); my $leftframe = $mw->Frame()->pack(-side => 'left'); my $n = 0; my @cbs = map { $leftframe->Checkbutton( -text => s/.{20}\K /\n/gr, # NOTE 1a) wrap if text too long -anchor => 'w', # NOTE 1) align buttons with -fill x -variable => \$values[$n++], -command => \&addextra, )->pack(-fill => 'x'); } @checkbuttonlabels; $mw->Frame(-bg => 'blue', -width => 3, # NOTE 2) separation line )->pack(-side => 'left', -fill => 'y'); my $rightframe = $mw->Frame()->pack(-side => 'left'); $rightframe->Label(-text => "The Right Side\nFrame", )->pack; $rightframe->Checkbutton(-text => "Special Notes?", -variable => \$wantspecial, -command => \&specialnotes, )->pack; my $subframe = $rightframe->Frame->pack; $subframe->Label(-text => 'Special Notes', -bg => 'blue', -fg => 'whit +e',, )->pack(-fill => 'x'); $notes = $subframe->Text()->pack; $_->packForget for @cbs[4, -1], $subframe; # NOTE initially not visibl +e MainLoop; -M $0 < 0 and exec $0; # for testing FIXME sub specialnotes # pack/packForget special notes { if( $wantspecial ) { $subframe->pack; $notes->delete('1.0' => 'end'); } else { $subframe->packForget; } } sub addextra { # NOTE 3) add additional checkbox $additionalcheckbutton++ or $cbs[-1]->pack(-fill => 'x'); if( $values[3] ) # NOTE 6) addextra for checkbutton three { $cbs[4]->pack(-fill => 'x', -after => $cbs[3] ); } else { $cbs[4]->packForget; } }

Uses pack/packForget for widgets that are transitory.

Replies are listed 'Best First'.
Re^2: Perl Tk, how to get File Browser, capture output to a Log file and format my checkboxes
by tybalt89 (Monsignor) on Mar 22, 2022 at 23:05 UTC

    Replace

    s/.{20}\K /\n/gr

    with

    s/(.{20}) /$1\n/gr

    if you are running with an old perl.

      Hello

      Yes, I am using and old perl version; it's the only one available to me. This is current perl -v, "This is perl, v5.6.1 built for i686-linux-thread-multi"

      So this perl version did not like the replacement s/(.{20}) /$1\n/gr , any other idea to satisfy this wrap around text ?

      I really would like to see your wrap around text code work.

      I was super busy at work today and feeling under the weather but I will post some updates to the GUI.

      Right now, only thing I can see having an issue is capturing the selection into a log file

      And adding a email utility with output of the selections.

      This is what I think the GUI to look

      A= Left side frame with ( about 4) long texts with a corresponding checkbox.

      B= 2 files chosen by using a file browser to select certain bank monthly statements.

      C= Lower frame is a "Special Note" selection that opens up for user input.

      D= Email button which sents an automated email with output of GUI to, say, daughter.

      diagram isn't working out; I tried. Sorry.

      xxxxxxxxxxxxx

      x A \t\t x \t\t B x

      xxxxxxxxxxxxxx

      x \t\t C \t\t x

      xxxxxxxxxxxxx

      x \t\t D \t\t x

      xxxxxxxxxxxxx

      Thanks for the help on formatting the checkboxes, adding the note pad too, and adding an extra checkbox

        > This is perl, v5.6.1

        Oh my God, according to perlhist, 5.6.1 is from 2001! It's more than 20 years old!

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
        --- pm11142273.pl.~54~ 2022-03-22 13:34:52.301454754 -0700 +++ pm11142273.pl 2022-03-23 06:39:44.750787662 -0700 @@ -5,7 +5,8 @@ use Tk; my $additionalcheckbutton = 0; -my @checkbuttonlabels = split /\n/, <<END; +# NOTE 1a) wrap if text too long +s/(.{20}) /$1\n/g for my @checkbuttonlabels = split /\n/, <<END; one two very long text entry for test purposes @@ -28,7 +29,7 @@ my @cbs = map { $leftframe->Checkbutton( - -text => s/.{20}\K /\n/gr, # NOTE 1a) wrap if text too + long + -text => $_, -anchor => 'w', # NOTE 1) align buttons with -fil +l x -variable => \$values[$n++], -command => \&addextra,
        So this perl version did not like the replacement s/(.{20}) /$1\n/gr

        Indeed not. 5.6.1 is far too old for the /r modifier. Pre-copy instead. eg:

        #!/usr/bin/env perl use strict; use warnings; my $in = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed + do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut en +im ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut + aliquip ex ea commodo consequat. Duis aute irure dolor in reprehende +rit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. E +xcepteur sint occaecat cupidatat non proident, sunt in culpa qui offi +cia deserunt mollit anim id est laborum.'; (my $out = $in) =~ s/(.{20}) /$1\n/g; print "In:\n$in\n\nOUT:\n$out\n";

        🦛

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-29 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found