Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 1 | from Tkinter import * |
| 2 | |
| 3 | # This is a program that tests the placer geom manager |
| 4 | |
| 5 | def do_motion(event): |
Guido van Rossum | 89cb67b | 1996-07-30 18:57:18 +0000 | [diff] [blame] | 6 | app.button.place(x=event.x, y=event.y) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 7 | |
| 8 | def dothis(): |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 9 | print('calling me!') |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 10 | |
| 11 | def createWidgets(top): |
| 12 | # make a frame. Note that the widget is 200 x 200 |
| 13 | # and the window containing is 400x400. We do this |
| 14 | # simply to show that this is possible. The rest of the |
| 15 | # area is inaccesssible. |
Guido van Rossum | 89cb67b | 1996-07-30 18:57:18 +0000 | [diff] [blame] | 16 | f = Frame(top, width=200, height=200, background='green') |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 17 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 18 | # place it so the upper left hand corner of |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 19 | # the frame is in the upper left corner of |
| 20 | # the parent |
Guido van Rossum | 89cb67b | 1996-07-30 18:57:18 +0000 | [diff] [blame] | 21 | f.place(relx=0.0, rely=0.0) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 22 | |
| 23 | # now make a button |
Guido van Rossum | 89cb67b | 1996-07-30 18:57:18 +0000 | [diff] [blame] | 24 | f.button = Button(f, foreground='red', text='amazing', command=dothis) |
| 25 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 26 | # and place it so that the nw corner is |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 27 | # 1/2 way along the top X edge of its' parent |
Guido van Rossum | 89cb67b | 1996-07-30 18:57:18 +0000 | [diff] [blame] | 28 | f.button.place(relx=0.5, rely=0.0, anchor=NW) |
| 29 | |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 30 | # allow the user to move the button SUIT-style. |
| 31 | f.bind('<Control-Shift-Motion>', do_motion) |
| 32 | |
| 33 | return f |
| 34 | |
| 35 | root = Tk() |
| 36 | app = createWidgets(root) |
| 37 | root.geometry("400x400") |
| 38 | root.maxsize(1000, 1000) |
| 39 | root.mainloop() |