新聞中心
這里有您想知道的互聯網營銷解決方案
創(chuàng)新互聯Python教程:如何使用Python編寫文本菜單
如何使用python編寫文本菜單

洞頭網站制作公司哪家好,找成都創(chuàng)新互聯!從網頁設計、網站建設、微信開發(fā)、APP開發(fā)、響應式網站設計等網站項目制作,到程序開發(fā),運營維護。成都創(chuàng)新互聯自2013年起到現在10年的時間,我們擁有了豐富的建站經驗和運維經驗,來保證我們的工作的順利進行。專注于網站建設就選成都創(chuàng)新互聯。
什么是文本菜單?
簡單一句話,現在你能看到的都是圖形菜單界面,退后20年,你能看到都是文本菜單界面。
文本菜單界面通常在以前比較老的DOS軟件里見到,例如老的PCTOOLS軟件,現在已經不容易找到了。
目前在windows系統(tǒng)下的軟件界面一般都是圖形菜單界面。
如何來實現文本菜單式的交互呢?
將menu.py,運行python menu.py即可。
menu.py代碼如下:
------menu.py----------
#!/usr/bin/evn python
# -*- coding: utf-8 -*-
#Edit: turnipsmart.com
import os,sys
running = True
menu = """
Main Menu
--------------------
1: Display Options
2: Config Options
3: Deteting
h: Help
q: Quit
--------------------
"""
menu_dict={
"h": "Please enter the options to be operated.",
"1": "df -h",
"2": "free -m",
"3": "netstat -lnt",
}
def commands(args):
cmd = menu_dict.get(args)
return cmd
if __name__ == "__main__":
os.system('cls')
print menu
while running:
cmd = raw_input("Input Your Commond:")
if cmd != 'q':
os.system('cls')
try:
print menu
if commands(cmd) != None:
#fo = os.popen(commands(cmd))
#print fo.read()
if cmd == '1':
print "cmd=1"
elif cmd == '2':
print "cmd=2"
elif cmd == '3':
print "cmd=3"
else:
print commands(cmd)
else:
print "Input is Wrong!"
except Exception,e:
print menu
print e
else:
print 'We will exit the menu.'
os.system('cls')
sys.exit()效果如下:
更多技術請關注Python視頻教程。
網站標題:創(chuàng)新互聯Python教程:如何使用Python編寫文本菜單
鏈接URL:http://m.5511xx.com/article/cccoodg.html


咨詢
建站咨詢
