Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 1 | from Tkinter import * |
| 2 | |
| 3 | # This is a program that makes a simple two button application |
| 4 | |
| 5 | |
| 6 | class New_Button(Button): |
| 7 | def callback(self): |
| 8 | print self.counter |
| 9 | self.counter = self.counter + 1 |
| 10 | |
| 11 | def createWidgets(top): |
| 12 | f = Frame(top) |
| 13 | f.pack() |
| 14 | f.QUIT = Button(f, {'text': 'QUIT', |
| 15 | 'fg': 'red', |
| 16 | 'command': top.quit}) |
| 17 | |
| 18 | f.QUIT.pack({'side': 'left', 'fill': 'both'}) |
| 19 | |
| 20 | |
| 21 | # a hello button |
| 22 | f.hi_there = New_Button(f, {'text': 'Hello'}) |
| 23 | # we do this on a different line because we need to reference f.hi_there |
| 24 | f.hi_there.config({'command' : f.hi_there.callback}) |
| 25 | f.hi_there.pack({'side': 'left'}) |
| 26 | f.hi_there.counter = 43 |
| 27 | |
| 28 | |
| 29 | |
| 30 | root = Tk() |
| 31 | createWidgets(root) |
| 32 | root.mainloop() |
| 33 | |