Danh mục

Web Client Programming with Perl-Chapter 7: Graphical Examples with Perl/Tk- P3

Số trang: 19      Loại file: pdf      Dung lượng: 39.99 KB      Lượt xem: 10      Lượt tải: 0    
Hoai.2512

Hỗ trợ phí lưu trữ khi tải xuống: 20,000 VND Tải xuống file đầy đủ (19 trang) 0
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tham khảo tài liệu web client programming with perl-chapter 7: graphical examples with perl/tk- p3, công nghệ thông tin, quản trị web phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Web Client Programming with Perl-Chapter 7: Graphical Examples with Perl/Tk- P3 Chapter 7: Graphical Examples with Perl/Tk- P3Our destinations list is an almost exact copy of the list youd see on the webpage. For ease in using, we placed U.S.A. as the first item in the list, andwe will select it as our default choice when we build the listbox:my $entry_f = $mw->Frame;$entry_f->pack(-expand => n, -fill => x);$entry_f->Label(-text => Airbill #: )->pack(-side=> left, -anchor => w, -expand => n, -fill => none);my $airbill = ;my $airbill_entry = $entry_f->Entry(-textvariable=> \$airbill, -width => 10);$airbill_entry->pack(-side => left, -anchor => w, -expand => y, -fill => x);The entry for the airbill requires a label so that the user knows what sort ofinput is expected. The default for the $airbill variable is blank. We save areference to the entry widget, so that we can set the focus of the applicationto it right before we enter the MainLoop :$entry_f->Label(-text => Date Shipped: )->pack(-side => left, -anchor => w, -expand => n, -fill => none);my %months;my $i = 1;foreach (qw(Jan Feb Mar Apr May Jun Jul Aug Sep OctNov Dec)) { $months{$_} = $i++;}my $fulltime = localtime;my ($month, $day, $year) = $fulltime =~ /\w+\s(\w+)\s(\d+)\s..:..:..\s..(\d\d)$/;$month = $months{$month};$month = 0$month if (length($month) < 2);$day = 0$day if (length($day) < 2);my $date = $month$day$year;$entry_f->Entry(-textvariable => \$date, -width => 6)->pack(-side => left, -anchor => w, -expand => n, -fill => none);We are going to use a default of today for the date field. The FedEx webpage expects it in the form of DayMonthYear, and digits with only onenumber require a leading zero. The string returned from localtime( ) gives usthe correct day, and we strip off the last two digits of the year. For the monthwe need to translate it to a number value from 01 - 12. We do this using a%months hash, where the keys are the string of the month, and the value thenumber of the month. We add leading zeros to the day and month ifnecessary.my $lb_f = $mw->Frame;$lb_f->pack(-anchor => n, -expand => n, -fill => x);$lb_f->Label(-text => Shipped To:)->pack(-side =>left, -anchor => w);We want a label to tell us what the listbox contains, so we create it first:my $scroll = $lb_f->Scrollbar;my $listbox = $lb_f->Listbox(-selectmode =>single, -height => 1, -yscrollcommand => [set,$scroll], -exportselection => 0);$scroll->configure(-command => [yview,$listbox]);$scroll->pack(-side => right, -fill => y);$listbox->pack(-side => left, -expand => yes, -fill => both);$listbox->insert(end, @destinations);$listbox->selection(set,0);Then we create the scrollbar and the listbox, and put our @destinations inthe listbox. Remember, we put the entry U.S.A first in our list, so when weselect the 0th element of the listbox, we get that entry selected. This is apretty large list, and it takes quite a while to scroll down to Zimbabwe.Although we didnt do it for our example here, you could set up your listboxso that if you typed a letter, it would scroll to the first entry starting with thatletter. Or you could put an additional entry, and search for any word startingwith those characters:my $response_f = $mw->Frame;$response_f->pack(-expand => y, -fill => both);$response_f->Label(-text => Response:)->pack(-anchor => w, -side => left);my $response_txt = ;$response_f->Label(-justify => left, -borderwidth=> 2, -relief => sunken, -textvariable => \$response_txt)->pack(-anchor => w, -side =>left, -expand =>y, -fill =>x);To show users what happened to their package (or any errors), we build alabel that displays any text in the $response_txt variable. To change the text,we simply reset $response_txt to another text string:my $bttn_f = $mw->Frame;$bttn_f->pack;$bttn_f->Button(-text => Exit, -command =>sub{exit}) ->pack(-side =>right, -anchor =>e);my $loop_bttn = $bttn_f->Button(-text => Loop, -command => \&loop_query);$loop_bttn->pack(-side => left, -anchor => w);$bttn_f->Button(-text => Query, -command =>\&do_query)-> pack(-side => left, -anchor => w);The buttons for our track program allow us to exit the program, start thequery loop, or manually do a query right now.my $pkg_tracker = new FedEx $url, $email;my $loop_id;$airbill_entry->focus;MainLoop;One last thing before we start the MainLoop to handle the GUI interaction.(Remember, this is diffe ...

Tài liệu được xem nhiều: