0
Linux에서 getch 및 progressbar Python 모듈을 결합하려고하는데 작동하지 않습니다. getch를 사용하여 진행률 표시 줄을 중단하기 위해 키보드 입력을 수신하려고하지만 getch 문을 삽입하면 진행률 표시 줄이 자동으로 업데이트를 거부하고 키보드의 버튼을 누를 때만 업데이트됩니다.Getch 및 progressbar
현재 사용중인 코드는 다음과 같습니다. 나는 ProgressBar2와 getch 모듈을 사용하고 있지만, tqdm과 내 자신의 getch 메소드를 사용해 보았다.
bar = progressbar.ProgressBar()
for i in range(101):
sleep(0.01)
bar.update(i)
ch = getch.getch()
getch 내 자신의 구현을 사용하여
, 나는 다음과 같은 코드에서 'sys.stdin.read (1)'라인으로 될 수있는 문제를 좁혀했습니다.fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno(), termios.TCSADRAIN)
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
msvcrt 모듈을 사용하면 아무런 문제가 없습니다.
기본적으로'file.read()'블록을 사용합니다. 이벤트 루프, 키보드 이벤트, 진행 바 위젯 (다른 것들 중에서)이있는 [urwid] (http://urwid.org/)는 어떻습니까? – blubberdiblub