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

I can't seem to ask this on google and get an answer.

On a terminal I run a while loop showing elements of an array, and ask for user input after each element.

while ( my $contact = pop(@names) ) { print "$contact\n"; print "Is this what you want? (y - n):"; $sel = <STDIN>; last if $sel =~ /y/i; }

How do I do this in a Tk script, using a yes and a no button?

Replies are listed 'Best First'.
Re: how do I show 1 record at a time in Tk
by choroba (Cardinal) on Jan 31, 2018 at 00:45 UTC
    For example, you can add lines to a Tk::Text . Just add the code to add a line to the button's command:
    #!/usr/bin/perl use warnings; use strict; use Tk; my @names = ( 'John Smith', 'Jane Doe', 'Francois Machin'); my $mw = 'MainWindow'->new; my $text = $mw->Text->pack; my $next; $next = $mw->Button(-text => 'Next', -command => sub { if (@names) { $text->insert('end', pop(@names) . "\n"); $next->configure(-text => 'Done') unless @ +names; } else { Tk::exit(); } })->pack; MainLoop();
    ($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,
Re: how do I show 1 record at a time in Tk
by AnomalousMonk (Archbishop) on Feb 01, 2018 at 13:28 UTC

    Here's an example of something with  Yes/No buttons for user selection.

    You may also be interested in Tk::BrowseEntry, described as "a poor man's ComboBox." This allows all possible selections to be displayed at once to a user in a scrollable list rather than presenting them one-by-one for selection.


    Give a man a fish:  <%-{-{-{-<

Re: how do I show 1 record at a time in Tk (Ask)
by Anonymous Monk on Feb 02, 2018 at 08:04 UTC
    You simply Ask, it has the added benefit of letting you choose Tk/Gtk/Wx/STDIO