home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyos2bin.zip / Demo / tkinter / www / www4.py < prev    next >
Text File  |  1996-11-27  |  518b  |  27 lines

  1. #! /usr/bin/env python
  2.  
  3. # www4.py -- display the contents of a URL in a Text widget
  4.  
  5. import sys
  6. import urllib
  7. from Tkinter import *
  8.  
  9. def main():
  10.     if len(sys.argv) != 2 or sys.argv[1][:1] == '-':
  11.         print "Usage:", sys.argv[0], "url"
  12.         sys.exit(2)
  13.     url = sys.argv[1]
  14.     fp = urllib.urlopen(url)
  15.  
  16.     text = Text()            # Create text widget
  17.     text.pack()            # Realize it
  18.  
  19.     while 1:
  20.         line = fp.readline()
  21.         if not line: break
  22.         text.insert('end', line)    # Append line to text widget
  23.  
  24.     text.mainloop()            # Start Tk main loop
  25.  
  26. main()
  27.