aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-01-10 17:07:40 +0000
committerGuido van Rossum <guido@python.org>1995-01-10 17:07:40 +0000
commitb8fe9b3fc8fbaa552cb4bcb7794bb45a7ee4b0a7 (patch)
treef4b9b620c4feb298345876751ee784a59f7788c9
parentImproved explanation of what's here (diff)
downloadcpython-b8fe9b3fc8fbaa552cb4bcb7794bb45a7ee4b0a7.tar.gz
cpython-b8fe9b3fc8fbaa552cb4bcb7794bb45a7ee4b0a7.tar.bz2
cpython-b8fe9b3fc8fbaa552cb4bcb7794bb45a7ee4b0a7.zip
menu-simple.py: fixed lay-out
bind-with-multiple-calls-per-event-type.py: new, or forgot to add earlier
-rw-r--r--Demo/tkinter/matt/bind-w-mult-calls-p-type.py43
-rw-r--r--Demo/tkinter/matt/menu-simple.py4
2 files changed, 45 insertions, 2 deletions
diff --git a/Demo/tkinter/matt/bind-w-mult-calls-p-type.py b/Demo/tkinter/matt/bind-w-mult-calls-p-type.py
new file mode 100644
index 00000000000..62beb096974
--- /dev/null
+++ b/Demo/tkinter/matt/bind-w-mult-calls-p-type.py
@@ -0,0 +1,43 @@
+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.
diff --git a/Demo/tkinter/matt/menu-simple.py b/Demo/tkinter/matt/menu-simple.py
index a1fc2fbad7f..1f46e2116ae 100644
--- a/Demo/tkinter/matt/menu-simple.py
+++ b/Demo/tkinter/matt/menu-simple.py
@@ -19,8 +19,8 @@ from Tkinter import *
# | New... |
# | Open... |
# | Print |
-# | | <-------- This is a MENU. The lines of text in the menu are
-# | | MENU ENTRIES
+# | | <------ This is a MENU. The lines of text in the menu are
+# | | MENU ENTRIES
# | +---------------+
# | Open Files > | file1 |
# | | file2 |