我试图在Linux上组合getch和progressbar Python模块,但我无法使其正常工作。我想使用getch侦听键盘输入以中断进度条,但是当我插入getch语句时,进度条拒绝自动更新,只有当我按下键盘上的按钮时才会更新。
下面是我目前使用的代码。我正在使用ProgressBar2和getch模块,但是我已经尝试使用tqdm和我自己的getch方法,但都没有用。
bar = progressbar.ProgressBar()
for i in range(101):
sleep(0.01)
bar.update(i)
ch = getch.getch()
当使用
我需要在Linux上制作一个c++程序,在这个程序中,所使用的程序只能输入整数,而不能输入字符和特殊字符。对于windows (我在getch()中使用了getch()头文件),下面的程序工作得很好。
#include<iostream>
#include<stdio.h>
#include<conio.h>
int getOnlyIntegers()
{
int ch;
long int num = 0;
do
{
ch = getch();
if(ch >= 48 &&am
我需要关闭一个在后台连续运行的线程,并在每次输入数字/字符时向主程序返回一组10个数字/字符,而不会阻塞主程序。仅供参考-以下代码现在应该可以在MS Windows和Linux上运行。下面是python 2.7x测试代码:
#!/usr/bin/env python
import thread
import time
try:
from msvcrt import getch # try to import Windows version
except ImportError:
def getch(): # define non-Windows version