Last active
August 29, 2015 14:05
-
-
Save jedie/ae4f974d00a417183b2c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
import Tkinter | |
import ScrolledText | |
example_content="""Lorem ipsum dolor sit amet, consetetur sadipscing elitr, | |
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. | |
At vero eos et accusam et justo duo dolores et ea rebum. | |
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. | |
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, | |
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, | |
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. | |
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.""" | |
class TkTest(object): | |
def __init__(self): | |
self.root = Tkinter.Tk() | |
self.root.title(__file__) | |
self.text = ScrolledText.ScrolledText( | |
master=self.root, height=30, width=80 | |
) | |
self.text.insert("end", example_content) | |
self.text.pack(side=Tkinter.LEFT, fill=Tkinter.Y) | |
self.text.bind("<Key>", self.event_key) | |
self.root.update() | |
def destroy(self, event=None): | |
self.root.quit() | |
def event_key(self, event): | |
print "<Key>" | |
return self._change_input(event) | |
def event_key_press(self, event): | |
print "<KeyPress>" | |
return self._change_input(event) | |
def event_key_relese(self, event): | |
print "<KeyRelease>" | |
return self._change_input(event) | |
def _change_input(self, event): | |
keycode = event.keycode | |
char = event.char | |
print "\tkeycode %s - char %s" % (keycode, repr(char)) | |
if not char or char not in string.letters: | |
print "\tignoriere Eingabe" | |
return | |
converted_char = char.upper() | |
self.text.insert(Tkinter.INSERT, converted_char) | |
return "break" | |
def mainloop(self): | |
self.root.mainloop() | |
if __name__ == "__main__": | |
tk_win = TkTest() | |
tk_win.mainloop() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment