get command items into submenu
Closed this issue · 2 comments
Yolotroll101 commented
I am trying to get multiple command items into a submenu. As far as I can tell, this is impossible. Please either tell me if it is possible, and if so, how, or if you are going to add it if it's not currently possible.
Yolotroll101 commented
I say that I think it's impossible because this happens in console:
AttributeError: 'CommandItem' object has no attribute 'start'
nickcounts commented
Not sure if you sorted this out, but it is possible. You need to add a submenu to its parent as a SubmenuItem
, which takes 3 arguments:
- string: The string to be displayed in the parent menu
- CursesMenu: the submenu object
- CursesMenu: the parent menu object
Here's a sample:
from cursesmenu import CursesMenu
from cursesmenu.items import *
menu = CursesMenu("TOP-LEVEL", "It has a subtitle too!")
command_item = CommandItem("Run a console command", "touch hello.txt")
function_item = FunctionItem("Call a function", input, ["Enter some input"])
submenu = CursesMenu("SUBMENU", "Submenu Subtitle String")
submenu.append_item(CommandItem("Make hello.txt", "touch hello.txt"))
submenu.append_item(CommandItem("Make world.txt", "touch world.txt"))
submenu.add_exit()
# Create the SubmenuItem object that will become selectable in the top-level menu
subMenuItemInTopMenu = SubmenuItem("Go to submenu", submenu, menu)
# Add 2 normal items and a submenu to the top-level menu
menu.append_item(command_item)
menu.append_item(function_item)
menu.append_item(subMenuItemInTopMenu)
menu.add_exit()
menu.show()