Debian Codegraph @

demos/tom

raw
1 #!/usr/bin/env perl
2 #
3 # Sample program to get Tom Christiansen going with Perl/Tk.
4
5 require 5.002;
6 use Tk;
7 use strict;
8 sub DoIt;
9
10 # Set up listbox
11 my(@messages) = ('First Message','Second Message','Third Message');
12
13 # Dummy function to be called
14 sub DoIt
15 {
16 print "DoIt(",join(',',@_),")\n";
17 }
18
19
20 # Initialze Tk
21 my $MW = MainWindow->new();
22
23 # Create a frame with a label and an entry to input user
24
25 my $user = (@ARGV) ? $ARGV[0] : $ENV{USER};
26 my $frame = $MW->Frame();
27 my$label = $frame->Label(-text => 'User : ');
28 my $entry = $frame->Entry(-textvariable => \$user);
29 $label->pack(-side => 'left');
30 $entry->pack(-side => 'right');
31 $frame->pack;
32
33 # Create the list box
34
35 my $listbox = $MW->Listbox();
36
37 # Fill in the list
38 $listbox->insert('end',@messages);
39 $listbox->pack;
40
41 # Create 'execute' button
42 my $execute = $MW->Button(-text => 'Execute',
43 -command => sub
44 {
45 DoIt($user,$listbox->get('active'));
46 $MW->destroy;
47 });
48 $execute->pack;
49
50 # Set 1st entry as default
51 $listbox->activate(0);
52
53 # Interact...
54 MainLoop();
55