我試圖在python中做一種終端克隆(只是爲了測試如果其他的和elif的聲明的力量)我想這樣做後,用戶輸入的東西進入終端,而且無論輸入的內容是否完整,都會返回到您可以輸入內容的位置。因此,可以說在用戶輸入Python程序循環
「幫助」
顯示的幫助菜單,然後終端輸入「終端~~ $」再次出現爲他們提供了輸入別的東西。
,或者如果用戶類型
「waejhgiuoahweioug」
終端狀態:「輸入無效」 我希望它再回到終端輸入。(「終端~~ $」) 我已經試過while循環,但是你似乎沒有工作。希望這是有道理的。這是到目前爲止我的代碼(我只有Tkinter的,所以我可以做的主循環()我沒有試圖讓該終端窗口(雖然這將是酷)!):
# 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()
那麼,究竟是什麼問題圍繞此循環?你到目前爲止的嘗試是什麼?你需要什麼'tkinter'? –
使用while循環做到這一點: –
使用while循環不會這樣的:笑 無效輸入: 終端V.1.0 APLHA 用於與終端 終端~~ $笑 無效的輸入幫助 鍵入help笑 無效的輸入:笑 無效輸入:笑 無效輸入:笑 無效輸入:笑 無效輸入:笑 無效輸入:笑 無效輸入:笑 無效輸入:笑 無效輸入:笑 無效輸入:笑 無限.... –