~ubuntu-branches/ubuntu/maverick/python3.1/maverick

« back to all changes in this revision

Viewing changes to Demo/tkinter/matt/packer-and-placer-together.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-03-23 00:01:27 UTC
  • Revision ID: james.westby@ubuntu.com-20090323000127-5fstfxju4ufrhthq
Tags: upstream-3.1~a1+20090322
ImportĀ upstreamĀ versionĀ 3.1~a1+20090322

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from tkinter import *
 
2
 
 
3
# This is a program that tests the placer geom manager in conjunction with
 
4
# the packer. The background (green) is packed, while the widget inside is placed
 
5
 
 
6
 
 
7
def do_motion(event):
 
8
    app.button.place(x=event.x, y=event.y)
 
9
 
 
10
def dothis():
 
11
    print('calling me!')
 
12
 
 
13
def 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.
 
18
    f = Frame(top, width=200, height=200, background='green')
 
19
 
 
20
    # note that we use a different manager here.
 
21
    # This way, the top level frame widget resizes when the
 
22
    # application window does.
 
23
    f.pack(fill=BOTH, expand=1)
 
24
 
 
25
    # now make a button
 
26
    f.button = Button(f, foreground='red', text='amazing', command=dothis)
 
27
 
 
28
    # and place it so that the nw corner is
 
29
    # 1/2 way along the top X edge of its' parent
 
30
    f.button.place(relx=0.5, rely=0.0, anchor=NW)
 
31
 
 
32
    # allow the user to move the button SUIT-style.
 
33
    f.bind('<Control-Shift-Motion>', do_motion)
 
34
 
 
35
    return f
 
36
 
 
37
root = Tk()
 
38
app = createWidgets(root)
 
39
root.geometry("400x400")
 
40
root.maxsize(1000, 1000)
 
41
root.mainloop()