Clarify portability and main program.
[python/dscho.git] / Demo / tkinter / www / www7.py
blobbe66dc89b4cae8f2ff5d0d04b1206d04caa26d25
1 #! /usr/bin/env python
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
8 import sys
9 import urllib
10 from Tkinter import *
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)
19 root = Tk()
20 root.title(url)
21 root.minsize(1, 1)
22 text = Text(root)
23 text.pack({'expand': 1, 'fill': 'both'})
25 while 1:
26 line = fp.readline()
27 if not line: break
28 text.insert('end', line)
29 root.update_idletasks() # Update display
31 root.mainloop()
33 main()