
บทความนี้ผมจะพาผู้อ่านไปแนะนำให้รู้จักกับโมดูล curses-menu ซึ่งเป็นโมดูลสำหรับสร้างเมบน terminal ในภาษา Python กันครับ
โมดูล curses-menu เป็นโมดูลสำหรับสร้างเมนูบน terminal ในภาษา Python เหมาะกับงานที่ต้องการ GUI และความรวดเร็วในการพัฒนา (เช่น เขียนสำหรับใช้งานแค่ตัวเอง เป็นต้น) โดยไม่ต้องเรียนรู้ GUI ให้ยุ่งยาก โมดูลนี้รองรับ Python 2 และ Python รองรับการทำงานบน Windows , Linux และ MacOS และใช้ MIT License
สำหรับผู้ใช้งาน Windows ต้องโหลดโมดูล curses มาติดตั้งก่อน โหลดไฟล์ whl มาติดตั้งได้จาก http://www.lfd.uci.edu/~gohlke/pythonlibs/#curses
สามารถติดได้จากคำสั่ง pip:
pip install curses-menu
ตัวอย่างการใช้งาน
[python]
# Import the necessary packages
from cursesmenu import *
from cursesmenu.items import *
# Create the menu
menu = CursesMenu("Title", "Subtitle")
# Create some items
# MenuItem is the base class for all items, it doesn't do anything when selected
menu_item = MenuItem("Menu Item")
# A FunctionItem runs a Python function when selected
function_item = FunctionItem("Call a Python function", input, ["Enter an input"])
# A CommandItem runs a console command
command_item = CommandItem("Run a console command", "touch hello.txt")
# A SelectionMenu constructs a menu from a list of strings
selection_menu = SelectionMenu(["item1", "item2", "item3"])
# A SubmenuItem lets you add a menu (the selection_menu above, for example)
# as a submenu of another menu
submenu_item = SubmenuItem("Submenu item", selection_menu, menu)
# Once we're done creating them, we just add the items to the menu
menu.append_item(menu_item)
menu.append_item(function_item)
menu.append_item(command_item)
menu.append_item(submenu_item)
# Finally, we call show to show the menu and allow the user to interact
menu.show()
[/python]
ผลลัพธ์

อ่านเอกสารการใช้งานได้ที่ http://curses-menu.readthedocs.org/en/latest/
หน้าเพจ http://github.com/pmbarrett314/curses-menu
ติดตามบทความต่อไปนะครับ
ขอบคุณครับ
0 ความคิดเห็น:
แสดงความคิดเห็น
แสดงความคิดเห็นได้ครับ :)