本文整理汇总了Python中menu.Menu.add_option方法的典型用法代码示例。如果您正苦于以下问题:Python Menu.add_option方法的具体用法?Python Menu.add_option怎么用?Python Menu.add_option使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类menu.Menu
的用法示例。
在下文中一共展示了Menu.add_option方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StartScene
# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import add_option [as 别名]
class StartScene(Scene):
def __init__(self, display):
super(StartScene, self).__init__(display)
self.menu = Menu()
def start_game():
self.next_scene = PlayScene(display)
def quit_game():
self.game_over = True
self.menu.add_option(("Start", start_game))
self.menu.add_option(("Quit", quit_game))
for i in range(0, self.menu.length()):
text, _ = self.menu.get(i)
display.put_string(2,
i,
text,
interface.WHITE,
interface.BLACK,
False)
display.put_char(0, 0, '>', interface.WHITE, interface.BLACK, True)
def update(self, display, key):
display.put_char(0,
self.menu.selection,
' ',
interface.WHITE,
interface.BLACK,
False)
if key == 'DOWN':
self.menu.select_next()
if key == 'UP':
self.menu.select_previous()
if key == 'SELECT':
_, callback = self.menu.get_selection()
callback()
return
display.put_char(0,
self.menu.selection,
'>',
interface.WHITE,
interface.BLACK,
True)
display.flush()
示例2: str
# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import add_option [as 别名]
user_in = ''
while True:
self.write_to_input('>>> ')
user_in = self.raw_input().strip()
self.write_to_log('User input: ' + user_in)
opt = self.current_menu.match(user_in)
if opt != None:
self.write_to_log("Matched: " + str(opt) + '\n')
#TODO should the following line be moved to Menu?
self.dispatcher.dispatch(opt.event)
return
self.write_to_log("INVALID INPUT\n")
if __name__ == "__main__":
from menu import Menu, MenuOption, MatchTemplate
m = Menu()
mt = MatchTemplate('partial_string', 'opt1')
m.add_option(MenuOption('opt1', [mt], None))
mt = MatchTemplate('partial_string', 'opt2')
m.add_option(MenuOption('opt2', [mt], None))
from event_dispatcher import EventDispatcher
dispatcher = EventDispatcher()
io_handler = IOHandler(dispatcher)
with io_handler:
io_handler.show_menu(m)
while True:
inp = io_handler.get_input()