本文整理汇总了Python中UI.choice方法的典型用法代码示例。如果您正苦于以下问题:Python UI.choice方法的具体用法?Python UI.choice怎么用?Python UI.choice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UI
的用法示例。
在下文中一共展示了UI.choice方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: doMenu
# 需要导入模块: import UI [as 别名]
# 或者: from UI import choice [as 别名]
def doMenu(self):
"""Executes the menu, executes user's chosen line, returns its index"""
while 1:
self.Items = self.Pages[self.PageIndex].Items
self.PossibleKeys = self.Pages[self.PageIndex].PossibleKeys
if self.DoCLS: clrScr()
self.Returned = 0
if self.Title != "": print("********"+ self.Title+ "********")
if self.PageIndex > 0: print("...")
for item in self.Items:
if item.IsSeparator:
print(item.Text)
else:
print(item.Key.upper(), item.Text)
if self.PageIndex < len(self.Pages)-1: print("...")
if self.CustomText != "": print (self.CustomText)
#Get player's choice
if self.HasReturn:
if len(self.Pages) > 1:
choice = UI.choice(self.PossibleKeys + [27, ord('\xe0')], "Enter your choice (ESC to return): ")
else:
choice = UI.choice(self.PossibleKeys + [27], "Enter your choice (ESC to return): ")
else:
if len(self.Pages) > 1:
choice = UI.choice(self.PossibleKeys + [ord('\xe0')], "Enter your choice: ")
else:
choice = UI.choice(self.PossibleKeys, "Enter your choice: ")
#If user has pressed ESC
if self.HasReturn and choice == 27:
self.Returned = 1
return 0
#If user has pressed an arrow key
if choice == ord('\xe0') and len(self.Pages) > 1:
choice = getch()
if ord(choice) == ord('M'): #Right arrow
self.PageIndex += 1
if self.PageIndex >= len(self.Pages):
self.PageIndex = 0
if ord(choice) == ord('K'): #Left arrow
self.PageIndex -= 1
if self.PageIndex < 0:
self.PageIndex = len(self.Pages)-1
# Restart the loop with new variables
continue
for Temp in self.Items:
if Temp.IsSeparator: continue
if chr(choice) == Temp.Key.lower():
ChosenItem = Temp
break
print ("")
print ("")
#Do an action described in MenuItem, wait for keypress if asked to, return user's choice
ChosenItem.CallBack()
if ChosenItem.WaitAfter: waitForKey()
return ChosenItem.ID