O'Reilly logo

Raspberry Pi Cookbook for Python Programmers by Tim Cox

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a boot-up menu

We shall now apply the methods introduced in the previous scripts and reapply them to create a menu that we can customize to present a range of quick-to-run commands and programs.

How to do it…

Create the menu.py script using the following code:

#!/usr/bin/python3 #menu.py from subprocess import call filename="menu.ini" DESC=0 KEY=1 CMD=2 print ("Start Menu:") try: with open(filename) as f: menufile = f.readlines() except IOError: print ("Unable to open %s" % (filename)) for item in menufile: line = item.split(',') print ("(%s):%s" % (line[KEY],line[DESC])) #Get user input running = True while(running): user_input = input() #Check input, and execute command for item in menufile: line = item.split(',') if (user_input == line[KEY]): ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required