| 1 |
#!/usr/bin/env perl |
| 2 |
# |
| 3 |
# Simple Tk script to create a button that prints "Hello, world". Click on |
| 4 |
# the button to terminate the program. |
| 5 |
# |
| 6 |
# The first line below imports the Tk objects into the application, the second |
| 7 |
# line creates the main window, the third through sixth lines create the button |
| 8 |
# and defines the code to execute when the button is pressed, the seventh line |
| 9 |
# asks the packer to shrink-wrap the application's main window around the |
| 10 |
# button, and the eight line starts the event loop. |
| 11 |
|
| 12 |
use Tk; |
| 13 |
$MW = MainWindow->new; |
| 14 |
$hello = $MW->Button( |
| 15 |
-text => 'Hello, world', |
| 16 |
-command => sub {print STDOUT "Hello, world\n"; exit;}, |
| 17 |
); |
| 18 |
$hello->pack; |
| 19 |
MainLoop; |