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): |
| 6 | app.button.place({'x' : event.x, |
| 7 | 'y' : event.y}) |
| 8 | |
| 9 | def dothis(): |
| 10 | print 'calling me!' |
| 11 | |
| 12 | def createWidgets(top): |
| 13 | # make a frame. Note that the widget is 200 x 200 |
| 14 | # and the window containing is 400x400. We do this |
| 15 | # simply to show that this is possible. The rest of the |
| 16 | # area is inaccesssible. |
| 17 | f = Frame(top, {'width' : '200', |
| 18 | 'height' : '200', |
| 19 | 'bg' : 'green'}) |
| 20 | |
| 21 | # place it so the upper left hand corner of |
| 22 | # the frame is in the upper left corner of |
| 23 | # the parent |
| 24 | f.place({'relx' : '0.0', |
| 25 | 'rely' : '0.0'}) |
| 26 | |
| 27 | # now make a button |
| 28 | f.button = Button(f, {'fg' : 'red', |
| 29 | 'text' : 'amazing', |
| 30 | 'command' : dothis}) |
| 31 | |
| 32 | # and place it so that the nw corner is |
| 33 | # 1/2 way along the top X edge of its' parent |
| 34 | f.button.place({'relx' : '0.5', |
| 35 | 'rely' : '0.0', |
| 36 | 'anchor' : 'nw'}) |
| 37 | |
| 38 | # allow the user to move the button SUIT-style. |
| 39 | f.bind('<Control-Shift-Motion>', do_motion) |
| 40 | |
| 41 | return f |
| 42 | |
| 43 | root = Tk() |
| 44 | app = createWidgets(root) |
| 45 | root.geometry("400x400") |
| 46 | root.maxsize(1000, 1000) |
| 47 | root.mainloop() |
| 48 | |