Guido van Rossum | dfa70a9 | 1995-01-10 17:05:37 +0000 | [diff] [blame^] | 1 | #! /usr/local/bin/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() |