Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b8fe9b3

Browse files
committed
menu-simple.py: fixed lay-out
bind-with-multiple-calls-per-event-type.py: new, or forgot to add earlier
1 parent d0c0633 commit b8fe9b3

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from Tkinter import *
2+
import string
3+
4+
# This program shows how to use a simple type-in box
5+
6+
class App(Frame):
7+
def __init__(self, master=None):
8+
Frame.__init__(self, master)
9+
self.pack()
10+
11+
self.entrythingy = Entry()
12+
self.entrythingy.pack()
13+
14+
# and here we get a callback when the user hits return. we could
15+
# make the key that triggers the callback anything we wanted to.
16+
# other typical options might be <Key-Tab> or <Key> (for anything)
17+
self.entrythingy.bind('<Key-Return>', self.print_contents)
18+
19+
# Note that here is where we bind a completely different callback to
20+
# the same event. We pass "+" here to indicate that we wish to ADD
21+
# this callback to the list associated with this event type. Not specifying "+" would
22+
# simply override whatever callback was defined on this event.
23+
self.entrythingy.bind('<Key-Return>', self.print_something_else, "+")
24+
25+
def print_contents(self, event):
26+
print "hi. contents of entry is now ---->", self.entrythingy.get()
27+
28+
29+
def print_something_else(self, event):
30+
print "hi. Now doing something completely different"
31+
32+
33+
root = App()
34+
root.master.title("Foo")
35+
root.mainloop()
36+
37+
38+
39+
# secret tip for experts: if you pass *any* non-false value as
40+
# the third parameter to bind(), Tkinter.py will accumulate
41+
# callbacks instead of overwriting. I use "+" here because that's
42+
# the Tk notation for getting this sort of behavior. The perfect GUI
43+
# interface would use a less obscure notation.

Demo/tkinter/matt/menu-simple.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
# | New... |
2020
# | Open... |
2121
# | Print |
22-
# | | <-------- This is a MENU. The lines of text in the menu are
23-
# | | MENU ENTRIES
22+
# | | <------ This is a MENU. The lines of text in the menu are
23+
# | | MENU ENTRIES
2424
# | +---------------+
2525
# | Open Files > | file1 |
2626
# | | file2 |

0 commit comments

Comments
 (0)