blob: 097121b233cdc1dcc508a9f49ab1c99edb838e43 [file] [log] [blame]
Guido van Rossumf06ee5f1996-11-27 19:52:01 +00001#! /usr/bin/env python
Guido van Rossumdfa70a91995-01-10 17:05:37 +00002
3# www8.py -- display the contents of a URL in a Text widget
4# - set window title
5# - make window resizable
6# - update display while reading
7# - vertical scroll bar
8
9import sys
10import urllib
11from Tkinter import *
12
13def main():
14 if len(sys.argv) != 2 or sys.argv[1][:1] == '-':
15 print "Usage:", sys.argv[0], "url"
16 sys.exit(2)
17 url = sys.argv[1]
18 fp = urllib.urlopen(url)
19
20 # Create root window
21 root = Tk()
22 root.title(url)
23 root.minsize(1, 1)
24
25 # The Scrollbar *must* be created first -- this is magic for me :-(
26 vbar = Scrollbar(root)
27 vbar.pack({'fill': 'y', 'side': 'right'})
28 text = Text(root, {'yscrollcommand': (vbar, 'set')})
29 text.pack({'expand': 1, 'fill': 'both', 'side': 'left'})
30
31 # Link Text widget and Scrollbar -- this is magic for you :-)
32 ##text['yscrollcommand'] = (vbar, 'set')
33 vbar['command'] = (text, 'yview')
34
35 while 1:
36 line = fp.readline()
37 if not line: break
38 text.insert('end', line)
39 root.update_idletasks()
40
41 root.mainloop()
42
43main()