Guido van Rossum | f06ee5f | 1996-11-27 19:52:01 +0000 | [diff] [blame^] | 1 | #! /usr/bin/env python |
Guido van Rossum | dfa70a9 | 1995-01-10 17:05:37 +0000 | [diff] [blame] | 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() |