我正在尝试用python制作一种终端克隆(只是为了测试if else和elif stations的功能),我希望在用户向终端输入一些东西之后,不管输入完成了什么,它都会返回到可以输入一些东西的地方。假设用户输入
'帮助'
“帮助”菜单出现,然后终端输入“终端~~$”再次出现,供他们键入其他内容。你知道吗
或者如果用户输入
“瓦伊吉乌瓦威格”
终端状态:“无效输入” 我想让它回到终端输入。。(“终端~~$”) 我试过while循环,但似乎不起作用。希望这是有意义的。这是我到目前为止的代码(我只有tkinter,所以我可以做mainloop(),我不想为终端创建一个窗口(尽管那会很酷!)地址:
# Import wait settings and tkinter... we only need tkinter for the mainloop() setting, so the game doesn't close when it's finished #
import time
from tkinter import *
print("Terminal V.1.0 Alpha")
print("Type help for assistance with the terminal")
# Input a command into the terminal! #
terminalInput = input("Terminal~~$ ")
# The inputs the terminal accepts #
if terminalInput == "help":
time.sleep(1)
print("HELP")
print("Type: 'text = your_text' to make the terminal speak!")
terminalInput = input("Terminal~~$ ")
if terminalInput == "text = " + terminalInput:
print("Terminal:\\" + terminalInput)
# Every input that the terminal does not accept #
else:
print("Invalid Input: " + terminalInput)
master = Tk()
谢谢大家的帮助!这是我到目前为止得到的!请试一试!你知道吗
一个简单的while循环可以帮助程序保持运行。你知道吗
代码如下:
试试这个:
相关问题 更多 >
编程相关推荐