Guido van Rossum | dfa70a9 | 1995-01-10 17:05:37 +0000 | [diff] [blame] | 1 | #! /usr/local/bin/python |
| 2 | |
| 3 | # www4.py -- display the contents of a URL in a Text widget |
| 4 | |
| 5 | import sys |
| 6 | import urllib |
| 7 | from Tkinter import * |
| 8 | |
| 9 | def main(): |
| 10 | if len(sys.argv) != 2 or sys.argv[1][:1] == '-': |
| 11 | print "Usage:", sys.argv[0], "url" |
| 12 | sys.exit(2) |
| 13 | url = sys.argv[1] |
| 14 | fp = urllib.urlopen(url) |
| 15 | |
| 16 | text = Text() # Create text widget |
| 17 | text.pack() # Realize it |
| 18 | |
| 19 | while 1: |
| 20 | line = fp.readline() |
| 21 | if not line: break |
| 22 | text.insert('end', line) # Append line to text widget |
| 23 | |
| 24 | text.mainloop() # Start Tk main loop |
| 25 | |
| 26 | main() |