| 
									
										
										
										
											1994-10-07 09:55:26 +00:00
										 |  |  | from Tkinter import * | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # this file demonstrates the creation of widgets as part of a canvas object | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Test(Frame): | 
					
						
							|  |  |  |     def printhi(self): | 
					
						
							| 
									
										
										
										
											2007-07-17 20:59:35 +00:00
										 |  |  |         print("hi") | 
					
						
							| 
									
										
										
										
											1994-10-07 09:55:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def createWidgets(self): | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  |         self.QUIT = Button(self, text='QUIT', foreground='red', | 
					
						
							|  |  |  |                            command=self.quit) | 
					
						
							|  |  |  |         self.QUIT.pack(side=BOTTOM, fill=BOTH) | 
					
						
							| 
									
										
										
										
											1994-10-07 09:55:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  |         self.draw = Canvas(self, width="5i", height="5i") | 
					
						
							| 
									
										
										
										
											1994-10-07 09:55:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  |         self.button = Button(self, text="this is a button", | 
					
						
							|  |  |  |                              command=self.printhi) | 
					
						
							| 
									
										
										
										
											1994-10-07 09:55:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  |         # note here the coords are given in pixels (form the | 
					
						
							|  |  |  |         # upper right and corner of the window, as usual for X) | 
					
						
							|  |  |  |         # but might just have well been given in inches or points or | 
					
						
							|  |  |  |         # whatever...use the "anchor" option to control what point of the | 
					
						
							|  |  |  |         # widget (in this case the button) gets mapped to the given x, y. | 
					
						
							|  |  |  |         # you can specify corners, edges, center, etc... | 
					
						
							|  |  |  |         self.draw.create_window(300, 300, window=self.button) | 
					
						
							| 
									
										
										
										
											1994-10-07 09:55:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  |         self.draw.pack(side=LEFT) | 
					
						
							| 
									
										
										
										
											1994-10-07 09:55:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def __init__(self, master=None): | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  |         Frame.__init__(self, master) | 
					
						
							|  |  |  |         Pack.config(self) | 
					
						
							|  |  |  |         self.createWidgets() | 
					
						
							| 
									
										
										
										
											1994-10-07 09:55:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | test = Test() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test.mainloop() |