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