
PyBox is the Python IDE I build. Everything below works with it, and the steps are the same ideas you would use anywhere. Get it on Google Play.
Why Tkinter fails on a plain Android Python
Tkinter wraps the Tk toolkit, and Tk on Linux draws through the X11 protocol. A normal Android has a different graphics stack, so Python code that calls tk.Tk() finds no display and fails with an error about a missing display.
What PyBox does
PyBox runs an X server inside the app, with a window manager embedded in it. A Tkinter script opens a real window on the PyBox desktop. The desktop has a panel with CPU, memory, FPS and clock, a taskbar, and a windows list. Touch, keyboard and clipboard are mapped through to X11.
A first example
import time
import tkinter as tk
root = tk.Tk()
root.title("Hello from PyBox")
root.geometry("420x240+120+100")
label = tk.Label(root, font=("Helvetica", 40))
label.pack(expand=True)
def tick():
label.config(text=time.strftime("%H:%M:%S"))
root.after(200, tick)
tick()
root.mainloop()
Create a project, paste this into main.py and press Run. The window appears on the desktop. The starter projects include Tkinter Calculator, Paint App, 2048, Minesweeper and Pendulum Lab to read next.
Tuning
- Touch mode: Direct clicks where you touch. Touchpad moves a cursor with your finger. There is two-finger tap for right-click and natural scrolling.
- Resolution and DPI: set in Settings, and apply the next time a GUI app starts.
- Fit to window: resizes the desktop on rotation and in split screen.
Tips
- Use
after()for animation, neverwhile Truein the main thread. - Give windows a
geometryso they do not stack in a corner. - Canvas drawing is the easiest way to get nice-looking results.
More in Run GUI apps on Android.
Questions
Does Tkinter work on Android?
Not in a plain console, because Tkinter draws through X11. PyBox runs an X11 server inside the app, so Tkinter windows open on its desktop.
Can I use pygame and Kivy the same way?
Yes. They also open windows on the PyBox X11 desktop. See the GUI apps guide.