Python 为什么不是';t输入在终端中是否正常工作?
我为终端中的设置编写了一个类(因为我不想创建一些UI):Python 为什么不是';t输入在终端中是否正常工作?,python,input,Python,Input,我为终端中的设置编写了一个类(因为我不想创建一些UI): 导入键盘,时间 类终端设置: 定义初始化(self,选项=[]): self.\u opts=选项 def启动(自): resopt={} 对于选择加入自我。\u选择: 打印(“\n”*10) 打印(“\n”*10) 打印(“\n”*10) 打印(“\n”*10) 打印(“\n”*10) 如果opt[“type”]=“yn”: 完成=错误 完成时!=正确: tmpres=输入(选项[“任务”]+“[Y/N]”) 如果tmpres.lowe
导入键盘,时间
类终端设置:
定义初始化(self,选项=[]):
self.\u opts=选项
def启动(自):
resopt={}
对于选择加入自我。\u选择:
打印(“\n”*10)
打印(“\n”*10)
打印(“\n”*10)
打印(“\n”*10)
打印(“\n”*10)
如果opt[“type”]=“yn”:
完成=错误
完成时!=正确:
tmpres=输入(选项[“任务”]+“[Y/N]”)
如果tmpres.lower()=“y”:
resopt[opt[“name”]=True
完成=正确
elif tmpres.lower()=“n”:
resopt[opt[“name”]=False
完成=正确
其他:
打印(“\n”*10)
打印(“\n”*10)
打印(“\n”*10)
打印(“\n”*10)
打印(“\n”*10)
打印(tmpres+“是无效答案。请使用[Y/N]”)
elif opt[“类型”]=“文本”:
tmpres=input(opt[“quest”]+“”)
resopt[opt[“name”]=tmpres
elif opt[“类型”]=“列表”:
完成=错误
sel=0
完成时!=正确:
打印(可选[“任务”])
计数=0
对于el in opt[“答案”]:
如果计数=sel:
打印(“[*]”+el)
其他:
打印(“[]”+el)
计数+=1
done2=False
而done2!=正确:
如果按下键盘上的键(“向下箭头”):
sel+=1
如果sel>=len(选项[“答案]):
sel=0
打印(“\n”*10)
打印(“\n”*10)
打印(“\n”*10)
打印(“\n”*10)
打印(“\n”*10)
计数=0
打印(可选[“任务”])
对于el in opt[“答案”]:
如果计数=sel:
打印(“[*]”+el)
其他:
打印(“[]”+el)
计数+=1
睡眠时间(0.25)
elif键盘。按下(“向上箭头”):
sel-=1
如果选择
import keyboard, time
class TerminalSettings:
def __init__(self, options=[]):
self._opts=options
def start(self):
resopt = {}
for opt in self._opts:
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
if opt["type"] == "yn":
done = False
while done != True:
tmpres = input(opt["quest"] + " [Y/N] ")
if tmpres.lower() == "y":
resopt[opt["name"]] = True
done = True
elif tmpres.lower() == "n":
resopt[opt["name"]] = False
done = True
else:
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
print(tmpres + " is a invalid answer. Use [Y/N]")
elif opt["type"] == "text":
tmpres = input(opt["quest"] + " ")
resopt[opt["name"]] = tmpres
elif opt["type"] == "list":
done = False
sel = 0
while done != True:
print(opt["quest"])
count = 0
for el in opt["answers"]:
if count == sel:
print("[*] " + el)
else:
print("[ ] " + el)
count += 1
done2 = False
while done2 != True:
if keyboard.is_pressed("down arrow"):
sel += 1
if sel >= len(opt["answers"]):
sel = 0
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
count = 0
print(opt["quest"])
for el in opt["answers"]:
if count == sel:
print("[*] " + el)
else:
print("[ ] " + el)
count += 1
time.sleep(0.25)
elif keyboard.is_pressed("up arrow"):
sel -= 1
if sel <= -1:
sel = len(opt["answers"])-1
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
count = 0
print(opt["quest"])
for el in opt["answers"]:
if count == sel:
print("[*] " + el)
else:
print("[ ] " + el)
count += 1
time.sleep(0.25)
elif keyboard.is_pressed("enter"):
done2 = True
done = True
resopt[opt["name"]] = opt["answers"][sel]
return resopt
ts = TerminalSettings([{"type":"list", "name":"version", "quest":"Version:", "answers":["1.1", "1.2", "2.1", "2.4"]}, {"type":"text", "name":"name", "quest":"What's your name?"}, {"type":"yn", "name":"doit", "quest":"Install?"}])
res = ts.start()
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
print(res)