This example might be slightly more involved but it was the quickest one I could find from what I've made. It's a simple menu that loads up scenes based on what button you use. It uses an array of arrays (scenes) to populate the menu and do stuff.
For example:
scenes[0][0] = 'Main' # the text to be displayed on the button
scenes[0][1] = load(res://scenes/main.tscn) # the scene to be loaded
The List control was added via the editor and wired up to _on_sceneList_item_selected via the editor as well. There's two signals you can consume for the click event, one of them doesn't send the index of the selected item. I'm using the one that does. I think the difference is that this one doesn't fire when you re-select the same item.
This exact code wasn't tested since I had to change some things for it to make sense out of the context of my game, but it should mostly work.
var scenes = []
func _ready():
_add_menus()
_populate_list()
# Fill up the list control with the Menu text
func _populate_list():
scene_list.clear()
for i in range(scenes.size()):
scene_list.add_item(scenes[i][0])
if(i > _normal_end):
scene_list.set_item_custom_bg_color(i, Color(.25, .25, 1))
# Fill up the array with the menu text and scenes to show.
func _add_menus():
scenes.append(['Main', load('res://scenes/main.tscn')])
scenes.append(['Unlockables', load('res://scenes/unlockables.tscn')])
scenes.append(['Customize', load('res://scenes/customize.tscn')])
scenes.append(['Achievements', load('res://scenes/achievements.tscn')])
scenes.append(['Options', load('res://scenes/options.tscn')])
_normal_end = scenes.size() -1
# the show_scene method is something I created that swaps
# out whatever sub-scene is currently loaded with the newly
# selected scene.
#
# it basically uses the index to get the scene out of the scenes array
# and then release the current scene and shows the new one.
func _on_sceneList_item_selected( index ):
show_scene(index)