Displayotron menu code



The python code provided with the display-o-tron HAT is great for easily making menus and navigating them. The only thing I couldn’t figure out is if there is a way to exit menu class function without hitting the escape button. Calling the left button or cancel button from the class redraw function doesn’t do it. How can I exit a menu class function from the class itself?


Currently you can only exit a plugin with an input action. IE: The class select or left direction handler must return True.

This is so to give you two options:

  • Pressing left can trigger an exit and take you up one menu item, just like navigating the menu as normal, or:
  • Selecting an “Exit” icon and hitting “Select” can trigger an exit

A simple example is the stocks plugin:

Since it uses Up/Down to control the displayed item, left is just bound to nothing but exit.

There’s currently no way to trigger an exit without user-interaction, but there may be a good reason to add it- what’s your use-case?


Thanks for the quick reply. It saves me from looking for a solution. I’m working on a network monitor that probes via SNMP various devices like router, access points, NAS, printer etc. and puts that information on the HAT including warnings if anything is not ok. The menu is for navigating through all monitored devices. The use case is that after navigating through the devices you can leave the PI and it will automatically switch back to the default (i.e.idle) handler which in my case shows WAN up and downloads speeds and logs that into files. Your answer means that after checking various devices you always need to return to the menu navigation (for automatic switch to the default handler) or select the default handler yourself. Not a big deal but just a little less user friendly.

PS. I noticed that the example code in menu.py under dothat/advanced has a menustructure with idle time function name “idle_timeout” which should be “idle_time” according to menu.py in the dot3k library.