blob: a1bb3b5790d61d9f7689c1b98fc76f8e03072cca [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):
7 print "hi"
8
9 def createWidgets(self):
Guido van Rossum89cb67b1996-07-30 18:57:18 +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
Guido van Rossum89cb67b1996-07-30 18:57:18 +000014 self.draw = Canvas(self, width="5i", height="5i")
Guido van Rossum35820f71994-10-07 09:55:26 +000015
Guido van Rossum89cb67b1996-07-30 18:57:18 +000016 self.button = Button(self, text="this is a button",
17 command=self.printhi)
Guido van Rossum35820f71994-10-07 09:55:26 +000018
19 # 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...
Guido van Rossum89cb67b1996-07-30 18:57:18 +000025 self.draw.create_window(300, 300, window=self.button)
Guido van Rossum35820f71994-10-07 09:55:26 +000026
Guido van Rossum89cb67b1996-07-30 18:57:18 +000027 self.draw.pack(side=LEFT)
Guido van Rossum35820f71994-10-07 09:55:26 +000028
29 def __init__(self, master=None):
30 Frame.__init__(self, master)
31 Pack.config(self)
32 self.createWidgets()
33
34test = Test()
35
36test.mainloop()