/Demo/tkinter/matt/placer-simple.py

http://unladen-swallow.googlecode.com/ · Python · 39 lines · 17 code · 10 blank · 12 comment · 0 complexity · 7cf52c2c805b61fe270db546353f6195 MD5 · raw file

  1. from Tkinter import *
  2. # This is a program that tests the placer geom manager
  3. def do_motion(event):
  4. app.button.place(x=event.x, y=event.y)
  5. def dothis():
  6. print 'calling me!'
  7. def createWidgets(top):
  8. # make a frame. Note that the widget is 200 x 200
  9. # and the window containing is 400x400. We do this
  10. # simply to show that this is possible. The rest of the
  11. # area is inaccesssible.
  12. f = Frame(top, width=200, height=200, background='green')
  13. # place it so the upper left hand corner of
  14. # the frame is in the upper left corner of
  15. # the parent
  16. f.place(relx=0.0, rely=0.0)
  17. # now make a button
  18. f.button = Button(f, foreground='red', text='amazing', command=dothis)
  19. # and place it so that the nw corner is
  20. # 1/2 way along the top X edge of its' parent
  21. f.button.place(relx=0.5, rely=0.0, anchor=NW)
  22. # allow the user to move the button SUIT-style.
  23. f.bind('<Control-Shift-Motion>', do_motion)
  24. return f
  25. root = Tk()
  26. app = createWidgets(root)
  27. root.geometry("400x400")
  28. root.maxsize(1000, 1000)
  29. root.mainloop()