Presentation is loading. Please wait.

Presentation is loading. Please wait.

PERL TK. 4.Use an IDE 3. Use the documentation! 2. Experiment. 1.Learn the basics.

Similar presentations


Presentation on theme: "PERL TK. 4.Use an IDE 3. Use the documentation! 2. Experiment. 1.Learn the basics."— Presentation transcript:

1 PERL TK

2 4.Use an IDE http://spectcl.sourceforge.net/ 3. Use the documentation! 2. Experiment. 1.Learn the basics

3 #Simple Window use Tk; $mw=MainWindow->new(); MainLoop ;

4 #Widget Tour use Tk; $mw=MainWindow->new(); $l=$mw->Label(-text => "this is a label"); $l->pack(); $b=$mw->Button(-text => "this is a button"); $b->pack(); $t=$mw->Text(-width => 10,height => 10); $t->insert(end,"this is a text"); $t->pack(); $e=$mw->Entry(width => 0); $e->insert(end,"this is an entry"); $e->pack(); $i=$mw->Listbox(height => 2); $i->insert(end,"listbox element1"); $i->insert(end,"listbox element2"); $i->selectionSet(1); $i->pack(); $be = $mw->BrowseEntry(-label => "Label", -variable => \$var); $be->insert("end", "opt1"); $be->insert("end", "opt2"); $be->insert("end", "opt3"); $be->pack(); MainLoop;

5

6 #BUTTONS use Tk; $mw=MainWindow->new( -name => "Buttons", -title => 'Button Demonstration', ); $l=$mw->Label(-text => "If you click on any of the four buttons below, the background of the button area will change to the color indicated in the button. You can press Tab to move among the buttons, then press Space to invoke the current button.", -wraplength => "4i", -justify => left); $l->pack(); foreach my $color (qw/PeachPuff1 LightBlue1 SeaGreen2 Yellow1/) { my $b = $mw->Button( -text => $color, -width => 10, -command => sub{$mw->configure(-background => lc($color))}, ); $b->pack(qw/-side top -expand yes -pady 2/); } MainLoop;

7

8 #LABELS use Tk; $mw=MainWindow->new( -name => "Label", -title => 'Label', ); $l=$mw->Label(- text => "Five labels are displayed below: three textual ones on the left, and an image label and a text label on the right. Labels are pretty boring because you can\'t do anything with them.", -wraplength => "4i", -justify => left); $l->pack(); my @pl = qw/-side left -expand yes -padx 10 -pady 10 -fill both/; my $left = $mw->Frame->pack(-side => left, -expand => yes, -padx => 10, -pady => 10, -fill => both); my $right = $mw->Frame->pack(@pl); @pl = qw/-side top -expand yes -pady 2 -anchor w/; my $left_l1 = $left->Label(-text => 'First label')->pack(@pl); my $left_l2 = $left->Label( -text => 'Second label, raised just for fun', -relief => 'raised', )- >pack(@pl); my $left_l3 = $left->Label( -text => 'Third label, sunken', -relief => 'sunken', )-pack(@pl); @pl = qw/-side top/; my $right_bitmap = $right->Label( -image => $mw->Photo(-file => Tk- >findINC('Xcamel.gif')), -borderwidth => 2, -relief => 'sunken', )->pack(@pl); my $right_caption = $right->Label(-text => 'Perl/Tk')->pack(@pl); MainLoop;

9

10 #RADIOBUTTON use Tk; sub click{ $mw->Dialog(-title => "Title", -buttons => ["OK"],text => $_[0])->Show(); } $mw=MainWindow->new( -name => "Radio", -title => 'Radio', ); $v=2; $b=$mw->Radiobutton(-command =>[ \&click,["The Radio 1 clicked “,\$v)],-variable => \$v,-value => 1); $b1=$mw->Radiobutton(-command =>[ \&click("The Radio 2 clicked",\$v1)],-variable => \$v,-value => 2); $b->pack(); $b1->pack(); MainLoop;

11

12 #Try to pack the "Button 10" at the left use Tk; $mw=MainWindow->new(); $mw->Button(-text => "Button1")->pack(qw/-side top -pady 2/); $mw->Button(-text => "Button2")->pack(qw/-side top -pady 2/); $mw->Button(-text => "Button3")->pack(qw/-side top -pady 2/); $mw->Button(-text => "Button4")->pack(qw/-side top -pady 2/); $mw->Button(-text => "Button 10")->pack(qw/-side left -expand yes - pady 2/); MainLoop;

13

14 use Tk; $mw=MainWindow->new(); $mw->Button(-text => "Button 10")->pack(qw/-side left -pady 2/); $mw->Button(-text => "Button1")->pack(qw/-side top - pady 2/); $mw->Button(-text => "Button2")->pack(qw/-side top - pady 2/); $mw->Button(-text => "Button3")->pack(qw/-side top - pady 2/); $mw->Button(-text => "Button4")->pack(qw/-side top -pady 2/); MainLoop;

15

16 #Make it to take all the extra space use Tk; $mw=MainWindow->new(); $mw->Button(-text => "Button 10", -height => 8 )->pack(qw/-side left -expand yes -pady 2/); $mw->Button(-text => "Button1")->pack(qw/- side top -expand yes -pady 2/); $mw->Button(-text => "Button2")->pack(qw/- side top -expand yes -pady 2/); $mw->Button(-text => "Button3")->pack(qw/- side top -expand yes -pady 2/); $mw->Button(-text => "Button4")->pack(qw/- side top -expand yes -pady 2/); MainLoop;

17

18 use Tk; $mw=MainWindow->new(); $mw->Button(-text => "Button 10", -height => 8 )- >pack(qw/-side left -expand yes -pady 2 fill y/); $mw->Button(-text => "Button1")->pack(qw/-side top -expand yes -pady 2/); $mw->Button(-text => "Button2")->pack(qw/-side top -expand yes -pady 2/); $mw->Button(-text => "Button3")->pack(qw/-side top -expand yes -pady 2/); $mw->Button(-text => "Button4")->pack(qw/-side top -expand yes -pady 2/); MainLoop;

19

20 #Make the "Button 1" and "Button 2" to be at the left,one under another use Tk; $mw=MainWindow->new(); $mw->Button(-text => "Button 10", -height => 8 )->pack(qw/-side left - expand yes -pady 2 -fill y/); $mw->Button(-text => "Button 20", -height => 8 )->pack(qw/-side left - expand yes -pady 2 -fill y/); $mw->Button(-text => "Button1")->pack(qw/-side top -expand yes - pady 2/); $mw->Button(-text => "Button2")->pack(qw/-side top -expand yes - pady 2/); $mw->Button(-text => "Button3")->pack(qw/-side top -expand yes -pady 2/); $mw->Button(-text => "Button4")->pack(qw/-side top - expand yes -pady 2/); MainLoop;

21

22 #Use Frames! use Tk; $mw=MainWindow->new(); $f1=$mw->Frame(); $f2=$mw->Frame(); $f1->Button(-text => "Button 10")->pack(qw/-side top -expand yes -pady 2 -fill y/); $f1->Button(-text => "Button 20")->pack(qw/-side top -expand yes -pady 2 -fill y/); $f2->Button(-text => "Button1")->pack(qw/-side top -expand yes -pady 2/); $f2->Button(-text => "Button2")->pack(qw/-side top -expand yes -pady 2/); $f2->Button(-text => "Button3")->pack(qw/-side top -expand yes -pady 2/); $f2->Button(-text => "Button4")->pack(qw/-side top -expand yes -pady 2/); $f1->pack(qw/-side left -expand yes -pady 2 -fill y/); $f2->pack(qw/-side left -expand yes - pady 2 -fill y/); MainLoop;

23

24 #Placer use Tk; $mw=MainWindow->new(); $mw->Button(-text => "Button1")->place(qw/-x 1 -y 1/); $mw->Button(-text => "Button2")->place(qw/-x 1 -y 1/); MainLoop;

25

26 use Tk; $mw=MainWindow->new(); $mw->Button(-text => "Button1")->place(qw/-x 4 -y 4/); $mw->Button(-text => "Button2")->place(qw/-x 1 -y 1/); MainLoop;

27

28 That is not all: Open the real application in the browser…


Download ppt "PERL TK. 4.Use an IDE 3. Use the documentation! 2. Experiment. 1.Learn the basics."

Similar presentations


Ads by Google