| 
									
										
										
										
											2009-01-04 18:53:28 +00:00
										 |  |  | from tkinter import * | 
					
						
							| 
									
										
										
										
											1994-10-07 09:55:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  | # This is a program that tests the placer geom manager in conjunction with | 
					
						
							| 
									
										
										
										
											1994-10-07 09:55:26 +00:00
										 |  |  | # the packer. The background (green) is packed, while the widget inside is placed | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def do_motion(event): | 
					
						
							| 
									
										
										
										
											1996-07-30 18:57:18 +00:00
										 |  |  |     app.button.place(x=event.x, y=event.y) | 
					
						
							| 
									
										
										
										
											1994-10-07 09:55:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def dothis(): | 
					
						
							| 
									
										
										
										
											2007-07-17 20:59:35 +00:00
										 |  |  |     print('calling me!') | 
					
						
							| 
									
										
										
										
											1994-10-07 09:55:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def createWidgets(top): | 
					
						
							|  |  |  |     # make a frame. Note that the widget is 200 x 200 | 
					
						
							|  |  |  |     # and the window containing is 400x400. We do this | 
					
						
							|  |  |  |     # simply to show that this is possible. The rest of the | 
					
						
							|  |  |  |     # area is inaccesssible. | 
					
						
							| 
									
										
										
										
											1996-07-30 18:57:18 +00:00
										 |  |  |     f = Frame(top, width=200, height=200, background='green') | 
					
						
							| 
									
										
										
										
											1994-10-07 09:55:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  |     # note that we use a different manager here. | 
					
						
							|  |  |  |     # This way, the top level frame widget resizes when the | 
					
						
							|  |  |  |     # application window does. | 
					
						
							| 
									
										
										
										
											1996-07-30 18:57:18 +00:00
										 |  |  |     f.pack(fill=BOTH, expand=1) | 
					
						
							| 
									
										
										
										
											1994-10-07 09:55:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # now make a button | 
					
						
							| 
									
										
										
										
											1996-07-30 18:57:18 +00:00
										 |  |  |     f.button = Button(f, foreground='red', text='amazing', command=dothis) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-07-18 06:16:08 +00:00
										 |  |  |     # and place it so that the nw corner is | 
					
						
							| 
									
										
										
										
											1994-10-07 09:55:26 +00:00
										 |  |  |     # 1/2 way along the top X edge of its' parent | 
					
						
							| 
									
										
										
										
											1996-07-30 18:57:18 +00:00
										 |  |  |     f.button.place(relx=0.5, rely=0.0, anchor=NW) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-10-07 09:55:26 +00:00
										 |  |  |     # allow the user to move the button SUIT-style. | 
					
						
							|  |  |  |     f.bind('<Control-Shift-Motion>', do_motion) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return f | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | root = Tk() | 
					
						
							|  |  |  | app = createWidgets(root) | 
					
						
							|  |  |  | root.geometry("400x400") | 
					
						
							|  |  |  | root.maxsize(1000, 1000) | 
					
						
							|  |  |  | root.mainloop() |