keepcalculator

06 Numbers and Powers

Python Kiosk Manager: Beginner Project Guide

Card No. 06·30135 · Updated · Standard formula, shown below

Session uptime 60 min
Idle check interval
0.5 min
Result
Session length
60 min
You entered
Idle timeout
5 min
You entered
You enter
Session length, Idle timeout
You get
Session uptime, Idle check interval
Rounding
0 dp · 1 dp

This guide walks you through building your first Python kiosk manager—a program that locks down a computer to run only your app, handles touch input, and restarts itself after a crash. You’ll learn the core components, see a minimal working example, and understand the security and reliability choices that separate a demo from a deployable kiosk.

Formula

The calculator above is a planning aid for your kiosk session logic. The uptime is simply the session length you set. The idle check interval is the idle timeout divided by 10, giving a reasonable polling frequency so the system notices inactivity within about 10% of the timeout window.

In symbols:

  • uptime = t (minutes)
  • idle_check = d / 10 (minutes)

Where t is the total session length in minutes and d is the idle timeout in minutes. The idle check interval is a design choice—polling more often than every d/10 wastes CPU; polling less often makes the timeout feel sluggish.

Worked Example

Using the defaults: session length = 60 minutes, idle timeout = 5 minutes.

  1. Uptime = 60 minutes.
  2. Idle check = 5 / 10 = 0.5 minutes (30 seconds).

So your kiosk should check for user input every 30 seconds. If no input is detected for 5 minutes, it should return to the home screen or lock the session.

What a Kiosk Manager Actually Does

A kiosk manager is a small program that turns a general-purpose computer into a single-purpose appliance. Think of a museum touchscreen, a self-checkout register, or a hotel check-in terminal. The manager’s job is to:

  • Start your application automatically on boot.
  • Keep the application in fullscreen, always on top.
  • Hide the mouse cursor (unless the app needs it).
  • Disable keyboard shortcuts that could exit the app (Alt+F4, Ctrl+Alt+Del, etc.).
  • Restart the app if it crashes or freezes.
  • Log out or reset to a clean state after a period of inactivity.

In Python, you typically build this by wrapping your main application with a supervisor loop. The supervisor monitors the child process and reacts to its exit code.

Choosing Your Approach: Fullscreen App vs. Browser

Before writing code, decide what your kiosk will run. Two common patterns:

  • Native GUI app (Tkinter, PyQt, Kivy): full control, offline, but more work to style and update.
  • Browser-based kiosk (Chrome/Chromium in kiosk mode): easy to build with HTML/CSS/JS, but requires a web server or local files, and you must lock down the browser.

For a first project, a Tkinter app is the simplest because it ships with Python and needs no extra dependencies. A browser kiosk is better if your content is already a website.

Minimal Python Kiosk Supervisor

Here’s a bare-bones supervisor that launches your app and restarts it if it exits:

import subprocess
import time
import sys

def run_kiosk():
    while True:
        print("Starting kiosk app...")
        proc = subprocess.Popen([sys.executable, "my_app.py"])
        proc.wait()
        print("App exited. Restarting in 3 seconds...")
        time.sleep(3)

if __name__ == "__main__":
    run_kiosk()

This loop runs my_app.py, waits for it to finish, then starts it again. It’s the core of any kiosk manager. In production, you’d add a maximum restart count to avoid a crash loop, and you’d log the exit code to diagnose problems.

Locking Down the System

Preventing the user from escaping your kiosk is the hardest part. On Windows, you can disable certain keys using a low-level keyboard hook (via pywin32 or keyboard library). On Linux, you can use xinput to disable the keyboard entirely, or run the kiosk in a dedicated X session. On macOS, you’d use kiosk mode in a browser or a native fullscreen app with App Nap disabled.

Common shortcuts to block:

  • Alt+F4 (close window)
  • Ctrl+Alt+Del (task manager / log out)
  • Alt+Tab (switch apps)
  • Super/Windows key (start menu)
  • Ctrl+Esc (start menu)

No Python-only solution is perfect on all platforms. For a truly locked-down kiosk, you should also set the OS to auto-login and use a restricted user account with no access to system settings.

Handling Idle Timeout and Resets

Most kiosks need to return to a home screen after a period of no use. You can track the last input event using libraries like pynput or by listening to mouse/keyboard events in your GUI framework. When the idle time exceeds your threshold, you reset the app to its initial state.

For a Tkinter app, a simple approach:

import tkinter as tk
import time

class KioskApp(tk.Tk):
    def __init__(self):
        super().__init__()
        self.last_activity = time.time()
        self.bind_all('<Key>', self.activity)
        self.bind_all('<Button>', self.activity)
        self.after(1000, self.check_idle)

    def activity(self, event):
        self.last_activity = time.time()

    def check_idle(self):
        if time.time() - self.last_activity > 300:  # 5 minutes
            self.reset_to_home()
        self.after(1000, self.check_idle)

    def reset_to_home(self):
        # destroy all widgets and recreate home screen
        pass

This binds to all key and mouse events, updates a timestamp, and checks every second. When idle exceeds 300 seconds (5 minutes), it calls a reset function.

Common Problems and How to Fix Them

Beginners often hit these issues:

  • App crashes on startup – check your Python path and dependencies. The supervisor restarts blindly, so a syntax error will loop forever. Test the app standalone first.
  • Mouse cursor visible – in Tkinter, use root.config(cursor="none"). In PyQt, set setCursor(Qt.BlankCursor).
  • Screen turns off – disable power management in the OS, or send a keep-awake signal using win32api.SetThreadExecutionState on Windows.
  • Network drops – if your kiosk relies on a server, add retry logic and a local cache.
  • Touch input issues – on Windows, calibrate the touchscreen in OS settings. In Tkinter, touch events are treated as mouse clicks, so they usually work out of the box.

Security and Safety Considerations

A kiosk is only as secure as its weakest link. Even with a supervisor, a determined user can often break out if the OS isn’t hardened. For a public-facing kiosk:

  • Use a dedicated low-privilege user account.
  • Disable all system menus and shortcuts at the OS level.
  • Set a BIOS password to prevent booting from USB.
  • Use a write-protected storage medium (or an overlay filesystem) so changes don’t persist.
  • Keep the OS and Python up to date with security patches.

Do not rely on Python alone to secure the machine. The supervisor is a convenience layer, not a security boundary.

Alternatives to Building Your Own

If you don’t want to maintain a custom manager, consider existing open-source tools:

  • Firefox Kiosk – run Firefox in kiosk mode with a single URL.
  • Chromium – chrome --kiosk flag.
  • Kiosk mode in Windows – Windows 10/11 has a built-in Assigned Access feature.
  • Raspberry Pi + Kiosk – many tutorials for booting directly into a browser.

These tools handle the hard parts of locking down the OS, but they are less flexible than a custom Python manager. For a learning project, building your own is a great way to understand the internals.

Frequently Asked Questions

Do I need a Raspberry Pi to build a kiosk?

No. Any computer running Windows, macOS, or Linux can be turned into a kiosk. A Raspberry Pi is popular because it’s cheap and small, but the same Python code runs on a regular PC.

Can I use PyInstaller to make a standalone kiosk executable?

Yes. PyInstaller bundles your Python script and dependencies into a single .exe (or Linux binary). This simplifies deployment—you don’t need Python installed on the target machine. Just be aware that some antivirus software may flag PyInstaller executables as suspicious.

How do I prevent the kiosk from being closed with Alt+F4?

In Tkinter, you can override the close event with root.protocol("WM_DELETE_WINDOW", lambda: None). For a global block, you need a keyboard hook (Windows) or a custom X session (Linux). The protocol method works for the window close button, but Alt+F4 sends the same event, so it’s usually sufficient.

What is the best way to update a kiosk app remotely?

Build a simple update mechanism: have the kiosk check a server for a new version string, download a new executable or script, and replace itself on restart. Alternatively, use a configuration management tool like Ansible or a package manager like apt for Linux. For a beginner, a simple script that pulls from a Git repository on boot is a practical start.

My kiosk app freezes but doesn’t crash. How do I detect that?

Add a watchdog timer. In your main loop, update a timestamp every second. Have a separate thread that checks if the timestamp is older than, say, 30 seconds. If so, kill the app and let the supervisor restart it. This is a common pattern in embedded systems.

Is it safe to run a kiosk with a public network connection?

It can be, but you must secure the network. Use a firewall to block all inbound connections, and only allow outbound traffic to the services you need. If the kiosk handles sensitive data, use HTTPS and avoid storing credentials on the device. Treat the kiosk as untrusted and isolate it from your internal network.

Related

Formula used
in t | Session length | min | 60 | 1 | 1440
in d | Idle timeout | min | 5 | 1 | 120
out uptime | Session uptime | min | t | 0
out idle_check | Idle check interval | min | d / 10 | 1

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →