(py-indent-right, py-outdent-left): new commands, bound to C-c C-r and
[python/dscho.git] / Demo / tkinter / guido / tst.py
blobe30fc8429090ac4afb6d9d3c45ec32e7b93404cf
1 # tst.py
2 from Tkinter import *
3 import sys
5 def do_hello():
6 print 'Hello world!'
8 class Quit(Button):
9 def __init__(self, master=None, cnf={}):
10 Button.__init__(self, master,
11 ({'name': 'quit',
12 'text': 'Quit',
13 'command': self.quit},
14 cnf))
16 class Stuff(Canvas):
17 def enter(self, e):
18 print 'Enter'
19 self.itemconfig('current', {'fill': 'red'})
20 def leave(self, e):
21 print 'Leave'
22 self.itemconfig('current', {'fill': 'blue'})
23 def __init__(self, master=None, cnf={}):
24 Canvas.__init__(self, master,
25 {'width': 100, 'height': 100})
26 Canvas.config(self, cnf)
27 self.create_rectangle(30, 30, 70, 70,
28 {'fill': 'blue', 'tags': 'box'})
29 Canvas.bind(self, 'box', '<Enter>', self.enter)
30 Canvas.bind(self, 'box', '<Leave>', self.leave)
32 class Test(Frame):
33 text = 'Testing'
34 num = 1
35 def do_xy(self, e):
36 print (e.x, e.y)
37 def do_test(self):
38 if not self.num % 10:
39 self.text = 'Testing 1 ...'
40 self.text = self.text + ' ' + `self.num`
41 self.num = self.num + 1
42 self.testing['text'] = self.text
43 def do_err(self):
44 1/0
45 def do_after(self):
46 self.testing.invoke()
47 self.after(10000, self.do_after)
48 def __init__(self, master=None):
49 Frame.__init__(self, master)
50 self['bd'] = 30
51 Pack.config(self)
52 self.bind('<Motion>', self.do_xy)
53 self.hello = Button(self, {'name': 'hello',
54 'text': 'Hello',
55 'command': do_hello,
56 Pack: {'fill': 'both'}})
57 self.testing = Button(self)
58 self.testing['text'] = self.text
59 self.testing['command'] = self.do_test
60 Pack.config(self.testing, {'fill': 'both'})
61 self.err = Button(self, {'text': 'Error',
62 'command': self.do_err,
63 Pack: {'fill': 'both'}})
64 self.quit = Quit(self, {Pack: {'fill': 'both'}})
65 self.exit = Button(self,
66 {'text': 'Exit',
67 'command': lambda: sys.exit(0),
68 Pack: {'fill': 'both'}})
69 self.stuff = Stuff(self, {Pack: {'padx': 2, 'pady': 2}})
70 self.do_after()
72 test = Test()
73 test.master.title('Tkinter Test')
74 test.master.iconname('Test')
75 test.master.maxsize(500, 500)
76 test.testing.invoke()
78 # Use the -i option and type ^C to get a prompt
79 mainloop()