Skip to main content

Termux GUI: Write a graphical Termux program in Python

·
Categories Smartphones Termux Tutorials
Table of Contents

Termux uses the “Termux:GUI” plugin to call Android components and display a graphical interface.

Note: this article discusses the Python data binding provided by Termux GUI. If you want to run an X11 graphical interface, see Termux X11

You can write GUIs with Python or C data bindings. The author provides many methods, allowing you to build interfaces with short snippets of code.

1. Install Termux:GUI
#

  1. Download and install Termux:GUI from F-Droid.

  2. Open Termux and install python-binding

pip install termuxgui

2. Example program
#

  1. Install the termux-gui-package package in Termux
pkg install termux-gui-package
  1. Enter the downloaded scripts directory. The files inside can be executed directly; for example, the following program opens a file browser:
termux-gui-files
  1. Or you can write a python program yourself:
import termuxgui as tg
import sys
import time
with tg.Connection() as c:
    name = sys.argv
    a = tg.Activity(c,dialog=True)
    layout = tg.LinearLayout(a)
    if len(name) == 1:
        tv = tg.TextView(a, "Hello Anonymous")
    else:
        tv = tg.TextView(a, "Hello "+name[1])
    time.sleep(5)
  1. Run python hello.py Ivon; the result is shown below:

3. References
#

Related


Thank you for reading. Public comments are not available on this website. I write to explore ideas honestly, not to chase social engagement or traffic. I would be glad to hear your thoughts after reading the article with care. If you found any errors, technical issues, or would like to share feedback, feel free to contact me via the email listed on the About page.