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

  1. #! /usr/bin/env python
  2.  
  3. # www8.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. # - vertical scroll bar
  8.  
  9. import sys
  10. import urllib
  11. from Tkinter import *
  12.  
  13. def main():
  14.     if len(sys.argv) != 2 or sys.argv[1][:1] == '-':
  15.         print "Usage:", sys.argv[0], "url"
  16.         sys.exit(2)
  17.     url = sys.argv[1]
  18.     fp = urllib.urlopen(url)
  19.  
  20.     # Create root window
  21.     root = Tk()
  22.     root.title(url)
  23.     root.minsize(1, 1)
  24.  
  25.     # The Scrollbar *must* be created first -- this is magic for me :-(
  26.     vbar = Scrollbar(root)
  27.     vbar.pack({'fill': 'y', 'side': 'right'})
  28.     text = Text(root, {'yscrollcommand': (vbar, 'set')})
  29.     text.pack({'expand': 1, 'fill': 'both', 'side': 'left'})
  30.  
  31.     # Link Text widget and Scrollbar -- this is magic for you :-)
  32.     ##text['yscrollcommand'] = (vbar, 'set')
  33.     vbar['command'] = (text, 'yview')
  34.  
  35.     while 1:
  36.         line = fp.readline()
  37.         if not line: break
  38.         text.insert('end', line)
  39.         root.update_idletasks()
  40.  
  41.     root.mainloop()
  42.  
  43. main()
  44.