Tham khảo tài liệu 'web client programming with perl-chapter 7: graphical examples with perl/tk- p1', 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ả | Chapter 7 Graphical Examples with Perl Tk- P1 The Tk extension to Perl can be used to create a Graphical User Interface GUI to your Perl programs on UNIX. Why would you want to do this Several reasons such as ease of use or to be able to display HTML nicely. Instead of just writing a cool script you could go as far as writing your own custom browser. In this chapter we show a few examples of Tk-based web clients which go beyond the command-line interface that we ve been using so far in this book 1 xword a dictionary client track a graphical version of the FedEx example shown in Chapter 6. webping an at-a-glance display of the status of multiple web servers One caveat about Tk and it s a serious one. At this writing the Tk module to Perl also known as pTk only runs on UNIX machines with the X Window System. While the Tk extension to the Tcl language has been successfully ported to Microsoft Windows the Perl port is still pending although it is rumored to be in the works. Still even with its limited availability we think the ability to give your programs an easy-to-use graphical interface is important enough to devote a chapter to it. And who knows--by the time you re reading this the pTk port to Windows might already be completed and this whole paragraph may be moot. A Brief Introduction to Tk Tk was originally developed by John Ousterhout as an extension to his Tcl language for providing a graphical user interface for the X Window System. It was ported to Perl soon afterwards Nick Ing-Simmons did most of the work to make it functional as a module with Perl. You can get Tk from any CPAN archive http CPAN . The Tk extension provides an easy way to draw a window put widgets into it such as buttons check boxes entry fields menus etc. and have them perform certain actions based on user input. A simple Hello World program would look like this 1 usr bin perl -w 2 use Tk 3 my mw MainWindow- new 4 mw- Button -text Hello World -command sub exit - pack 5 MainLoop