blob: fc048596a77a6ef33e80fc805eb818512346a881 [file] [log] [blame]
Guido van Rossum35820f71994-10-07 09:55:26 +00001from Tkinter import *
2
3# This is a program that makes a simple two button application
4
5
6class New_Button(Button):
7 def callback(self):
Collin Winter6f2df4d2007-07-17 20:59:35 +00008 print(self.counter)
Tim Peters182b5ac2004-07-18 06:16:08 +00009 self.counter = self.counter + 1
10
Guido van Rossum35820f71994-10-07 09:55:26 +000011def createWidgets(top):
12 f = Frame(top)
13 f.pack()
Guido van Rossum89cb67b1996-07-30 18:57:18 +000014 f.QUIT = Button(f, text='QUIT', foreground='red', command=top.quit)
Guido van Rossum35820f71994-10-07 09:55:26 +000015
Guido van Rossum89cb67b1996-07-30 18:57:18 +000016 f.QUIT.pack(side=LEFT, fill=BOTH)
Guido van Rossum35820f71994-10-07 09:55:26 +000017
18 # a hello button
Guido van Rossum89cb67b1996-07-30 18:57:18 +000019 f.hi_there = New_Button(f, text='Hello')
Guido van Rossum35820f71994-10-07 09:55:26 +000020 # we do this on a different line because we need to reference f.hi_there
Guido van Rossum89cb67b1996-07-30 18:57:18 +000021 f.hi_there.config(command=f.hi_there.callback)
22 f.hi_there.pack(side=LEFT)
Guido van Rossum35820f71994-10-07 09:55:26 +000023 f.hi_there.counter = 43
24
25
Guido van Rossum35820f71994-10-07 09:55:26 +000026root = Tk()
27createWidgets(root)
28root.mainloop()