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

  1. #! /usr/bin/env python
  2.  
  3. # www7.py -- display the contents of a URL in a Text widget
  4. # - set window title
  5. # - make window resizable
  6. # - update display while reading
  7.  
  8. import sys
  9. import urllib
  10. from Tkinter import *
  11.  
  12. def main():
  13.     if len(sys.argv) != 2 or sys.argv[1][:1] == '-':
  14.         print "Usage:", sys.argv[0], "url"
  15.         sys.exit(2)
  16.     url = sys.argv[1]
  17.     fp = urllib.urlopen(url)
  18.  
  19.     root = Tk()
  20.     root.title(url)
  21.     root.minsize(1, 1)
  22.     text = Text(root)
  23.     text.pack({'expand': 1, 'fill': 'both'})
  24.  
  25.     while 1:
  26.         line = fp.readline()
  27.         if not line: break
  28.         text.insert('end', line)
  29.         root.update_idletasks()        # Update display
  30.  
  31.     root.mainloop()
  32.  
  33. main()
  34.