File: bind-w-mult-calls-p-type.py

package info (click to toggle)
python2.7 2.7.3-6%2Bdeb7u2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 71,112 kB
  • sloc: ansic: 424,479; python: 416,704; sh: 12,085; asm: 10,846; makefile: 4,201; objc: 775; exp: 416; cpp: 207; xml: 73
file content (44 lines) | stat: -rw-r--r-- 1,550 bytes parent folder | download | duplicates (20)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from Tkinter import *
import string

# This program  shows how to use a simple type-in box

class App(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.pack()

        self.entrythingy = Entry()
        self.entrythingy.pack()

        # and here we get a callback when the user hits return. we could
        # make the key that triggers the callback anything we wanted to.
        # other typical options might be <Key-Tab> or <Key> (for anything)
        self.entrythingy.bind('<Key-Return>', self.print_contents)

        # Note that here is where we bind a completely different callback to
        # the same event. We pass "+" here to indicate that we wish to ADD
        # this callback to the list associated with this event type.
        # Not specifying "+" would simply override whatever callback was
        # defined on this event.
        self.entrythingy.bind('<Key-Return>', self.print_something_else, "+")

    def print_contents(self, event):
        print "hi. contents of entry is now ---->", self.entrythingy.get()


    def print_something_else(self, event):
        print "hi. Now doing something completely different"


root = App()
root.master.title("Foo")
root.mainloop()



# secret tip for experts: if you pass *any* non-false value as
# the third parameter to bind(), Tkinter.py will accumulate
# callbacks instead of overwriting. I use "+" here because that's
# the Tk notation for getting this sort of behavior. The perfect GUI
# interface would use a less obscure notation.