blob: 84d3ee09d84d4564d41299fef04798c295b5c769 [file] [log] [blame]
Guido van Rossum35820f71994-10-07 09:55:26 +00001from Tkinter import *
2
Tim Peters182b5ac2004-07-18 06:16:08 +00003# This is a program that tests the placer geom manager in conjunction with
Guido van Rossum35820f71994-10-07 09:55:26 +00004# the packer. The background (green) is packed, while the widget inside is placed
5
6
7def do_motion(event):
Guido van Rossum89cb67b1996-07-30 18:57:18 +00008 app.button.place(x=event.x, y=event.y)
Guido van Rossum35820f71994-10-07 09:55:26 +00009
10def dothis():
Collin Winter6f2df4d2007-07-17 20:59:35 +000011 print('calling me!')
Guido van Rossum35820f71994-10-07 09:55:26 +000012
13def createWidgets(top):
14 # make a frame. Note that the widget is 200 x 200
15 # and the window containing is 400x400. We do this
16 # simply to show that this is possible. The rest of the
17 # area is inaccesssible.
Guido van Rossum89cb67b1996-07-30 18:57:18 +000018 f = Frame(top, width=200, height=200, background='green')
Guido van Rossum35820f71994-10-07 09:55:26 +000019
Tim Peters182b5ac2004-07-18 06:16:08 +000020 # note that we use a different manager here.
21 # This way, the top level frame widget resizes when the
22 # application window does.
Guido van Rossum89cb67b1996-07-30 18:57:18 +000023 f.pack(fill=BOTH, expand=1)
Guido van Rossum35820f71994-10-07 09:55:26 +000024
25 # now make a button
Guido van Rossum89cb67b1996-07-30 18:57:18 +000026 f.button = Button(f, foreground='red', text='amazing', command=dothis)
27
Tim Peters182b5ac2004-07-18 06:16:08 +000028 # and place it so that the nw corner is
Guido van Rossum35820f71994-10-07 09:55:26 +000029 # 1/2 way along the top X edge of its' parent
Guido van Rossum89cb67b1996-07-30 18:57:18 +000030 f.button.place(relx=0.5, rely=0.0, anchor=NW)
31
Guido van Rossum35820f71994-10-07 09:55:26 +000032 # allow the user to move the button SUIT-style.
33 f.bind('<Control-Shift-Motion>', do_motion)
34
35 return f
36
37root = Tk()
38app = createWidgets(root)
39root.geometry("400x400")
40root.maxsize(1000, 1000)
41root.mainloop()