1 #! /usr/local/bin/python
3 # www9.py -- display the contents of a URL in a Text widget
5 # - make window resizable
6 # - update display while reading
7 # - vertical scroll bar
15 if len(sys
.argv
) != 2 or sys
.argv
[1][:1] == '-':
16 print "Usage:", sys
.argv
[0], "url"
28 self
.root
.minsize(1, 1)
30 # The Scrollbar *must* be created first
31 self
.vbar
= Scrollbar(self
.root
)
32 self
.vbar
.pack({'fill': 'y', 'side': 'right'})
33 self
.text
= Text(self
.root
)
34 self
.text
.pack({'expand': 1, 'fill': 'both', 'side': 'left'})
36 # Link Text widget and Scrollbar
37 self
.text
['yscrollcommand'] = (self
.vbar
, 'set')
38 self
.vbar
['command'] = (self
.text
, 'yview')
41 # Load a new URL into the window
42 fp
= urllib
.urlopen(url
)
46 self
.text
.delete('0.0', 'end')
51 self
.text
.insert('end', line
)
52 self
.root
.update_idletasks()