1- Menus
1+ menus
22======
33
44This page contains tutorials about the :mod: `menus ` package.
@@ -28,12 +28,6 @@ This is a simple example to create paged menu
2828 menu.send(index)
2929 return False
3030
31- menu = PagedMenu(title = ' Welcome menu' , description = ' Choose an option:' , select_callback = my_select_callback)
32-
33- # Add options from 1 to 20
34- for i in range (1 , 20 ):
35- menu.append(PagedOption(f ' { i} ' , i))
36-
3731 def my_select_callback (menu , index , option ):
3832 '''
3933 Called whenever a selection was made.
@@ -45,6 +39,21 @@ This is a simple example to create paged menu
4539 # Make it sticky
4640 return menu
4741
42+ menu = PagedMenu(
43+ title = ' Welcome menu' ,
44+ description = ' Choose an option:' ,
45+ select_callback = my_select_callback
46+ )
47+
48+ # Add options from 1 to 20
49+ for i in range (1 , 20 ):
50+ menu.append(PagedOption(f ' { i} ' , i))
51+
52+ # Register close button to send back the menu
53+ @menu.register_close_callback
54+ def _on_close_menu (menu , index ):
55+ menu.send(index)
56+
4857
4958 Creating SimpleMenu
5059--------------------------
@@ -72,26 +81,35 @@ This is a simple example to create simple menu
7281 menu.send(index)
7382 return False
7483
84+ def my_menu_select_callback (menu , index , option ):
85+ '''
86+ Called whenever a selection was made.
87+ '''
88+
89+ if option.value == ' yes' :
90+ SayText2(' Thank you for accepting the rules!' ).send(index)
91+
92+ # player have selected no option
93+ else :
94+ # Kick player for selecting no option
95+ Player(index).kick(' You have to accept the rules!' )
7596
7697 menu = SimpleMenu()
98+
7799 # Tell the current time
78100 menu.append(Text(f " Current Time: { time.strftime(' %H:%M:%S' )} " ))
101+
79102 # Add empty line
80103 menu.append(Text(' ' ))
81104 menu.append(Text(' Do you accept the rules?' ))
82105 menu.append(Text(' ' ))
106+
83107 # Add in menu options
84108 menu.append(SimpleOption(1 , ' Yes' , ' yes' ))
85109 menu.append(SimpleOption(2 , ' No' , ' no' ))
86- menu.select_callback= my_menu_select_callback
87110
111+ menu.select_callback= my_menu_select_callback
88112
89- def my_menu_select_callback (menu , index , option ):
90- if option.value == ' yes' :
91- SayText2(' Thank you for accepting the rules!' ).send(index)
92- # Player selected no option
93- else :
94- Player(index).kick(' You have to accept the rules!' )
95113
96114 Creating ListMenu
97115--------------------------
0 commit comments