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 | # www5.py -- display the contents of a URL in a Text widget |
| 4 | # - set window title |
| 5 | |
| 6 | import sys |
| 7 | import urllib |
| 8 | from Tkinter import * |
| 9 | |
| 10 | def main(): |
| 11 | if len(sys.argv) != 2 or sys.argv[1][:1] == '-': |
| 12 | print "Usage:", sys.argv[0], "url" |
| 13 | sys.exit(2) |
| 14 | url = sys.argv[1] |
| 15 | fp = urllib.urlopen(url) |
| 16 | |
| 17 | root = Tk() |
| 18 | root.title(url) # Set window manager title |
| 19 | text = Text(root) |
| 20 | text.pack() |
| 21 | |
| 22 | while 1: |
| 23 | line = fp.readline() |
| 24 | if not line: break |
| 25 | text.insert('end', line) |
| 26 | |
| 27 | text.mainloop() |
| 28 | |
| 29 | main() |