| 1 |
from Tkinter import * |
| 2 |
|
| 3 |
|
| 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', foreground='red', command=top.quit) |
| 15 |
|
| 16 |
f.QUIT.pack(side=LEFT, fill=BOTH) |
| 17 |
|
| 18 |
|
| 19 |
f.hi_there = New_Button(f, text='Hello') |
| 20 |
|
| 21 |
f.hi_there.config(command=f.hi_there.callback) |
| 22 |
f.hi_there.pack(side=LEFT) |
| 23 |
f.hi_there.counter = 43 |
| 24 |
|
| 25 |
|
| 26 |
root = Tk() |
| 27 |
createWidgets(root) |
| 28 |
root.mainloop() |