blob: 3cbf93720f4bbcb2181422781885c83c3bd932aa [file] [log] [blame]
Guido van Rossum35820f71994-10-07 09:55:26 +00001from Tkinter import *
2
3# this file demonstrates the creation of widgets as part of a canvas object
4
5class Test(Frame):
6 def printhi(self):
Collin Winter6f2df4d2007-07-17 20:59:35 +00007 print("hi")
Guido van Rossum35820f71994-10-07 09:55:26 +00008
9 def createWidgets(self):
Tim Peters182b5ac2004-07-18 06:16:08 +000010 self.QUIT = Button(self, text='QUIT', foreground='red',
11 command=self.quit)
12 self.QUIT.pack(side=BOTTOM, fill=BOTH)
Guido van Rossum35820f71994-10-07 09:55:26 +000013
Tim Peters182b5ac2004-07-18 06:16:08 +000014 self.draw = Canvas(self, width="5i", height="5i")
Guido van Rossum35820f71994-10-07 09:55:26 +000015
Tim Peters182b5ac2004-07-18 06:16:08 +000016 self.button = Button(self, text="this is a button",
17 command=self.printhi)
Guido van Rossum35820f71994-10-07 09:55:26 +000018
Tim Peters182b5ac2004-07-18 06:16:08 +000019 # note here the coords are given in pixels (form the
20 # upper right and corner of the window, as usual for X)
21 # but might just have well been given in inches or points or
22 # whatever...use the "anchor" option to control what point of the
23 # widget (in this case the button) gets mapped to the given x, y.
24 # you can specify corners, edges, center, etc...
25 self.draw.create_window(300, 300, window=self.button)
Guido van Rossum35820f71994-10-07 09:55:26 +000026
Tim Peters182b5ac2004-07-18 06:16:08 +000027 self.draw.pack(side=LEFT)
Guido van Rossum35820f71994-10-07 09:55:26 +000028
29 def __init__(self, master=None):
Tim Peters182b5ac2004-07-18 06:16:08 +000030 Frame.__init__(self, master)
31 Pack.config(self)
32 self.createWidgets()
Guido van Rossum35820f71994-10-07 09:55:26 +000033
34test = Test()
35
36test.mainloop()