Mehrere Schlüssel-Ereignis-Bindings in Tkinter - "Strg + E" "- Befehl (Apfel) + E" etc

Mac OS X 10.6.6 - Tkinter

Ich soll binden mehrere-wichtige Ereignisse, und während ich habe eine effbot Artikel und der Tk-Mann-Seiten, ich habe nicht in der Lage diese Arbeit zu machen, richtig. Ich bin neu hier.

Ich hatte gemischten Erfolg. Ich habe in der Lage zu bekommen Umschalt + Buchstabentaste, nicht aber die Kontrolle oder die Befehlstaste (Apple-Taste). Was ich wirklich tun möchte, ist das Command + Buchstabe und Strg + den Buchstaben, so würde es theoretisch funktionieren in Windows und OS X.

Ich will, dass es funktioniert auf Fenster-Ebene, so dass ich mit root. Vielleicht gibt es einen besseren Weg. Unten ist das, was ich versucht habe:

root.bind('<Shift-E>', self.pressedCmdE)   # Works
root.bind('e', self.pressedCmdE)           # Works
root.bind('<Command-E>', self.pressedCmdE) # Does Not Work
#root.bind('<Mod1-E>', self.pressedCmdE)   #   # Do Mod1, M1, and
#root.bind('<M1-E>', self.pressedCmdE)     #   # Command mean the same thing?

Seltsam, wenn ich drücken Sie alt/option + (E, N, oder andere) es entsteht ein Fehler. Ist es die Interaktion mit PythonLauncher?

2011-06-16 16:19:22.618 Python[1546:d07] An uncaught exception was raised
2011-06-16 16:19:22.621 Python[1546:d07] *** -[NSCFString characterAtIndex:]: Range or index out of bounds
2011-06-16 16:19:22.622 Python[1546:d07] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFString characterAtIndex:]: Range or index out of bounds'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x00007fff85b397b4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x00007fff848b90f3 objc_exception_throw + 45
    2   CoreFoundation                      0x00007fff85b395d7 +[NSException raise:format:arguments:] + 103
    3   CoreFoundation                      0x00007fff85b39564 +[NSException raise:format:] + 148
    4   Foundation                          0x00007fff866eb5e1 -[NSCFString characterAtIndex:] + 97
    5   Tk                                  0x0000000100759bcf Tk_SetCaretPos + 663
    6   Tk                                  0x000000010075fd94 Tk_MacOSXSetupTkNotifier + 699
    7   Tcl                                 0x000000010061d2ae Tcl_DoOneEvent + 297
    8   _tkinter.so                         0x00000001001d9be9 init_tkinter + 1132
    9   Python                              0x0000000100089187 PyEval_EvalFrameEx + 15317
    10  Python                              0x000000010008acce PyEval_EvalCodeEx + 1803
    11  Python                              0x000000010008935e PyEval_EvalFrameEx + 15788
    12  Python                              0x000000010008acce PyEval_EvalCodeEx + 1803
    13  Python                              0x000000010008ad61 PyEval_EvalCode + 54
    14  Python                              0x00000001000a265a Py_CompileString + 78
    15  Python                              0x00000001000a2723 PyRun_FileExFlags + 150
    16  Python                              0x00000001000a423d PyRun_SimpleFileExFlags + 704
    17  Python                              0x00000001000b0286 Py_Main + 2718
    18  Python                              0x0000000100000e6c start + 52
)
terminate called after throwing an instance of 'NSException'
Abort trap
InformationsquelleAutor Ray | 2011-06-16
Schreibe einen Kommentar