blob: e79dd5c87506a8284fb189c055a56be7e3f3e31f [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):
8 print self.counter
9 self.counter = self.counter + 1
10
11def 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()
29