#!/usr/bin/perl use strict; use warnings; use feature qw/say/; #use diagnostics; use Tk; use Tk::Checkbox; my $mw = MainWindow->new; $mw->geometry("150x600"); $mw->title("ConMan"); # open my $FILE, '<', "ESSID", or die "Can't open file: $!"; # my @lines = <$FILE>; my @lines = ; my @checkbox; my $i = 0; foreach my $n (@lines) { chomp $n; my $number = $i++; # private copy for the anonymous sub below my $checkButton = $mw->Checkbutton( -text => "$n", -onvalue => 1, -offvalue => 0, -command => sub { $checkbox[$number] = defined $checkbox[$number] ? undef : $n; }, )->pack( -side => 'top', -anchor => 'nw' ); } my $connButton = $mw->Button( -text => "Connect", -command => sub { my @networks = grep { defined } @checkbox; if(@networks == 1) { say $networks[0]; } else { say "Select one network, please."; } } )->pack( -side => 'left', -anchor => 'sw', -padx => '5', -pady => '5' ); my $CancelButtons = $mw->Button( -text => "Close", -command => sub { say "Closing out ConnMan."; $mw->withdraw; exit 0; } )->pack( -side => 'right', -anchor => 'se', -padx => '5', -pady => '5' ); MainLoop; __DATA__ line1 line2 line3 line4 line5