Python: onkeypress without turtle window? -
my problem @ time is, want observe keypress through command
onkeypress(fun,"key")
but when import onkeypress , hear turtle, turtle window pops out, when run program. know how close again, or how not allow appear? coming answers, sorry bad english language (i'm high german , 13)
it might hard find experts in python turtle. however, if not limited library, may utilize next code key pressed user (last phone call gets key you):
class _getch: """gets single character standard input. not echo screen.""" def __init__(self): try: self.impl = _getchwindows() except importerror: self.impl = _getchunix() def __call__(self): homecoming self.impl() class _getchunix: def __init__(self): import tty, sys def __call__(self): import sys, tty, termios fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(sys.stdin.fileno()) ch = sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.tcsadrain, old_settings) homecoming ch class _getchwindows: def __init__(self): import msvcrt def __call__(self): import msvcrt homecoming msvcrt.getch() getch = _getch()
code comes this article
python window turtle-graphics
No comments:
Post a Comment