in reply to Re^2: Feedback for programming a UI in Perl
in thread Feedback for programming a UI in Perl

I don't know what you mean by trigger.

#!/usr/bin/perl # http://perlmonks.org/?node_id=1170638 use strict; use warnings; use Tk; use Tk::JPEG; use Image::Size; my $file = '../smalltux.gif'; my ($w, $h) = imgsize($file); my $mw = new MainWindow; my $one = $mw->Frame()->pack; my $labelone = $one->Label(-text => 'Panel One', -fg => 'red', )->pack(-side => 'left'); $one->Button(-text => 'On', -command => sub { $labelone->configure(-fg => 'green')}, )->pack(-side => 'left'); $one->Button(-text => 'Off', -command => sub { $labelone->configure(-fg => 'red')}, )->pack(-side => 'left'); my $c = $mw->Canvas(-width => $w, -height => $h )->pack(); my $im = $c->Photo(-file =>$file); $c->createImage(0, 0, -image => $im, -anchor => 'nw'); my $two = $mw->Frame()->pack; my $labeltwo = $two->Label(-text => 'Panel One', -fg => 'red', )->pack(-side => 'left'); $two->Button(-text => 'On', -command => sub { $labeltwo->configure(-fg => 'green')}, )->pack(-side => 'left'); $two->Button(-text => 'Off', -command => sub { $labeltwo->configure(-fg => 'red')}, )->pack(-side => 'left'); MainLoop;

Replies are listed 'Best First'.
Re^4: Feedback for programming a UI in Perl
by Anonymous Monk on Aug 29, 2016 at 03:51 UTC

    I like Tk because it lets me write a 15 puzzle in 15 lines :)

    #!/usr/bin/perl use Tk; use strict; my @a = map $_->[0], sort {$a->[1] <=> $b->[1]} map [$_, rand], 0..15; my ($mw, $hole) = new MainWindow; sub xy { -row => $_[0] % 4, -column => int $_[0] / 4 } for my $ii (0..15) { my ($num, $i, $but) = ($a[$ii], $ii); $hole = $i, next unless $num; $but = $mw->Button(-text => $num, -width => 2, -height => 2, -comman +d => sub { $but->grid(xy(($i,$hole) = ($hole,$i))) if abs $i - $hole == 4 or abs $i - $hole == 1 and int $i/4 == int $hole/4 })->grid(xy $i); } MainLoop;

    hehehe

      WoW.. some master is still hanging around!

      I love Tk because let me (an ignorant in many fields) to write a full featured (or well satisfiyng me) program with easy.

      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re^4: Feedback for programming a UI in Perl
by Anonymous Monk on Aug 30, 2016 at 01:24 UTC

    I wrote a Battleship generator for Battleship solitaire puzzle generator

    Then I thought about this node and added the Tk portion for a better display, also clicking a button exposes the data under it.

    #!/usr/bin/perl # http://perlmonks.org/?node_id=1170733 use strict; use warnings; my $sea = (('~' x 10) . "\n") x 10; sub transpose { local $_ = $sea; tr/<>^v/^v<>/; $sea = ''; $sea .= "\n" while s/^(.)/ $sea .= $1; '' /gem; } for my $ship ( 4,3,3,2,2,2,1,1,1,1 ) { my @places; push @places, $-[0] while $sea =~ /(?=~{$ship})/g; substr $sea, $places[rand @places], $ship, ('O', '<>', '<#>', '<##>' )[$ship - 1]; transpose; } 0.5 < rand and transpose; # for random direction start print $sea; my @chars = $sea =~ /./g; use Tk; # for http://perlmonks.org/?node_id=1170638 my $mw = new MainWindow; for my $y (0..9) { for my $x (0..9) { my $char = shift @chars; my $b = $mw->Button( -font => 'courier 24', -text => ' ', )->grid(-row => $y, -column => $x); $b->configure(-command => sub {$b->configure(-text => $char) }); } } MainLoop;

        Hey, where are the snippets from other UIs? Are they too difficult to program in?

        They're all the same difficulty-wise

        The snippets are all out there for those who are interested to find, there is some even on perlmonks

Re^4: Feedback for programming a UI in Perl
by Anonymous Monk on Aug 29, 2016 at 03:42 UTC

    Oops, typo in second panel