• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
Maker Hacks

Maker Hacks

Ideas, news & tutorials for makers and hackers – Arduino/Raspberry Pi, 3D printing, robotics, laser cutting, and more

  • Home
  • About
  • 3D Printing
  • Laser Cutting
  • YouTube
  • Free Arduino Course
  • Recommendations
  • Contact

Linux Automation Tips: Create a Boot/Start Menu with Python

You are here: Home / Software / Linux Automation Tips: Create a Boot/Start Menu with Python
FacebookTweetPin
Author: Chris Garrett

pi entertainment centre

You may have seen in the Maker Hacks Facebook Group the latest iteration of my Raspberry Pi based entertainment center. It’s now got to the point where I need a boot menu, so I thought I would share the code and implementation with you!

python linux boot menu

Code

See the full code in the Gist.

First we need to add the readchar module. Use pip3 install readchar.

This module simplifies interpreting keypresses, otherwise, we would need to look up the escape codes and such ourselves. Not fun.

The other module is the os module which allows us to clear the screen (os.system('clear')) and launch programs.

Once you have done this it is a simple case to do an infinite while loop and look for the specific keys we want the user to choose from.

Remember I said the module helps us? Check out where looking for the Enter key is made much easier:

if(key == readchar.key.ENTER):

We launch the programs using os.system – you can get more clever with it but this works for our purposes.

import os
import readchar
# place in your start up file:
# sudo nano ./.bashrc

def menu():
    while True:
        os.system('clear')
        print("\t\tChoose from the following options:\n\n")
        print("\t\tk: Kodi")
        print("\t\tr: Retro Pi")
        print("\t\tx: XWindows")
        print("\n\t\tEnter to quit to terminal\n\n\n")
        # Read a key
        key = readchar.readkey()
        if(key == 'k'):
            print("Launch Kodi")
            os.system("kodi")
        elif(key == 'r'):
            print("Launch RetroPie")
            os.system("emulationstation")
        elif(key == 'x'):
            print("Launch X Windows")
            os.system("startx")
        elif(key == readchar.key.ENTER):
            print("Exit to terminal")
            break
        else:
            print("Please choose an option from above")

if __name__ == "__main__":
    menu()

Related

Category: SoftwareTag: Hacks, linux, making, python, technology
FacebookTweetPin

About Chris Garrett

Marketing nerd by day, maker, retro gaming, tabletop war/roleplaying nerd by night. Co-author of the Problogger Book with Darren Rowse. Husband, Dad, 🇨🇦 Canadian.

Check out Retro Game Coders for retro gaming/computing.

☕️ Support Maker Hacks on Ko-Fi and get exclusive content and rewards!

Previous Post:GrovePi Gyro, Buttons, DisplaysUsing Grove Sensors, Buttons, and Displays, with Raspberry Pi and Python
Next Post:Running Raspberry Pi AND Arduino for the Best of Both WorldsRaspberry Pi and Arduino

Sidebar

  • Facebook
  • Twitter
  • Instagram
  • YouTube

Recently Popular

  • Gweike Cloud Review
  • How to choose the right 3D printer for you
  • Glowforge Review – Glowforge Laser Engraver Impressions, Plus Glowforge Versus Leading Laser Cutters
  • Prusa i3 Mk3S Review
  • Best 3D Printing Facebook Groups
  • xTool D1 Pro Laser Cutter Review
  • Elegoo Mars Review – Review of the Elegoo Mars MSLA Resin 3D Printer
  • Glowforge ‘Pass-Through’ Hack: Tricking the Front Flap of the Glowforge with Magnets to Increase Capacity
  • How to Make a DIY “Internet of Things” Thermometer with ESP8266/Arduino
  • Wanhao Duplicator i3 Review
  • IKEA 3D Printer Enclosure Hack for Wanhao Di3
  • Creality CR-10 3d printer review – Large format, quality output, at a low price!
  • 3D Printed Tardis with Arduino Lights and Sounds
  • Anet A8 Review – Budget ($200 or less!) 3D Printer Kit Review
  • Make your own PEI 3D printer bed and get every print to stick!
  • Upgrading the Wanhao Di3 from Good to Amazing
  • How to Install and Set Up Octopi / Octoprint
  • Creality CR-10 S5 Review
  • Glowforge Air Filter Review
  • Thunder Laser Review
  • 3D Printing
  • CNC
  • Hardware
  • Laser Cutting
  • News
  • Retro Computing
  • Software

amiga amos arduino basic programming budget buying cad cnc commodore corexy c programming creality crypto doctor who emulation esp32 esp8266 filament fpga glowforge Hacks Ideas kids lighting linux Makes making Monoprice Parts pc props prusa python raspberry pi ratrig resin Reviews robots software sounds technology tips upgrades wanhao xtool

.

Maker Hacks Blog Copyright © 2023 · All Rights Reserved · Powered by Mai Theme