Hello Monks,
I am trying to learn Tk module. I want to have a checkbutton for each US state and upon submit i want to know what checkbuttons have been checked.
I was able to get the data entered from the textbox(Entry) but not the checkbuttons.
Any help is really appreciated.
Thank you
Akhila
Below is my code approach:
#! /usr/bin/perl -w
use Tk;
my $mw = new MainWindow;
$mw->geometry("300x300");
$mw->title("Perl Tk Checkbutton");
my $check_frame = $mw->Frame()->pack(-side=>"top");
my $label=$check_frame->Label(-text=>"Enter keywords")->pack(-side=>"t
+op")->pack();
my $entry = $check_frame->Entry()->pack();
#my $chk1 = $check_frame->Checkbutton(-text=>"Alaska",-variable=>"Alas
+ka")->pack();
my $state = "Alaska";
my $chk1 = $check_frame->Checkbutton(-text=>"Alaska",-command=>[\&chec
+k_sub,$state])->pack();
my $chk2 = $check_frame->Checkbutton(-text=>"Michigan",-variable=>"Mic
+higan")->pack();
my $button_frame = $mw->Frame()->pack(-side=>"bottom");
my $ok_button = $button_frame->Button(-text=>"Submit",-command=>\&chec
+k_sub)->pack(-side=>"left");
MainLoop;
sub check_sub{
print $_;
my @names = $entry->get();
print @names;
exit;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.