Class around PixMap objects that allows more python-like access. By Joe Strout.
[python/dscho.git] / Demo / tkinter / www / www8.py
blob097121b233cdc1dcc508a9f49ab1c99edb838e43
1 #! /usr/bin/env python
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
9 import sys
10 import urllib
11 from Tkinter import *
13 def 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)
20 # Create root window
21 root = Tk()
22 root.title(url)
23 root.minsize(1, 1)
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'})
31 # Link Text widget and Scrollbar -- this is magic for you :-)
32 ##text['yscrollcommand'] = (vbar, 'set')
33 vbar['command'] = (text, 'yview')
35 while 1:
36 line = fp.readline()
37 if not line: break
38 text.insert('end', line)
39 root.update_idletasks()
41 root.mainloop()
43 main()