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): |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 8 | print(self.counter) |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 9 | self.counter = self.counter + 1 |
| 10 | |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 11 | def createWidgets(top): |
| 12 | f = Frame(top) |
| 13 | f.pack() |
Guido van Rossum | 89cb67b | 1996-07-30 18:57:18 +0000 | [diff] [blame] | 14 | f.QUIT = Button(f, text='QUIT', foreground='red', command=top.quit) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 15 | |
Guido van Rossum | 89cb67b | 1996-07-30 18:57:18 +0000 | [diff] [blame] | 16 | f.QUIT.pack(side=LEFT, fill=BOTH) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 17 | |
| 18 | # a hello button |
Guido van Rossum | 89cb67b | 1996-07-30 18:57:18 +0000 | [diff] [blame] | 19 | f.hi_there = New_Button(f, text='Hello') |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 20 | # we do this on a different line because we need to reference f.hi_there |
Guido van Rossum | 89cb67b | 1996-07-30 18:57:18 +0000 | [diff] [blame] | 21 | f.hi_there.config(command=f.hi_there.callback) |
| 22 | f.hi_there.pack(side=LEFT) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 23 | f.hi_there.counter = 43 |
| 24 | |
| 25 | |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 26 | root = Tk() |
| 27 | createWidgets(root) |
| 28 | root.mainloop() |