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

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