Using tkinter Programs on Android: Provisional Guide

Version:  February 16, 2019
Author:  © M. Lutz, learning-python.com
Quick links:  View this guide's media
View the related Mergeall doc

This document describes how to run tkinter programs on Android in the Pydroid 3 app's IDE (its edit+run GUI). This app recently added fledgling but astonishing tkinter support, which allows many Python 3.X programs with tkinter GUIs to be run in source-code form on smartphones, with no or minimal changes. The focus here is on using this app to run both the complete application programs at this site as well as the tutorial examples in the book Programming Python, 4th Edition, but this coverage should apply to tkinter GUIs on Android devices in general.

Contents:

Preface

Before jumping into the details, here are a few administrative and global notes up front:

In the rest of this guide, you'll find brief and self-contained setup instructions for programs that work—and explanations for programs that don't—on smartphones and other Android devices. If you're willing to apply a few patches and tolerate some rough edges, the good news is that many Python/tkinter programs do work on Android today, and bring a wealth of existing software to this platform.

PP4E Examples

Most of the tutorial-level tkinter GUI examples in the book Programming Python, 4th Edition (a.k.a. PP4E) work unchanged in Pydroid 3. True to its educational focus, this makes Pydroid 3 viable as a platform for working along with the book's presentation.

GUI Look and Feel

Examples of this book's programs running on Android are captured in screenshots:

Here, here, here, here, here, here, and here

Orientation and Viewing Modes

Most of these examples yield smaller displays, which need not use tkinter fullscreen or maximized modes in Pydroid 3, but experiment with screen modes and phone orientations for best effect. Note that double-back exits in any viewing mode do not run tkinter exit handlers, and rotating the screen after a GUI is running may not work on some devices per usage notes ahead.

Running the Programs

To run PP4E book examples on your Android device, follow these steps:
  1. Install the Pydroid 3 app if needed from the Play Store.
  2. Download the book's examples package from this location to any writable folder on your phone, and unzip (i.e. extract) it.
  3. Run examples by opening their source-code files in the Pydroid 3 app's editor, and pressing the editor's big yellow run button. Most GUI examples reside in the unzipped example package's folder:
    PP4E-Examples-1.4/Examples/PP4E/Gui

Usage Notes

Also keep the following in mind when using PP4E book examples on Android:

Home-screen shortcuts
For quick two- or three-tap access to any book example, make a home-screen shortcut (a.k.a. link) to either the example's source-code file, or the package's Gui folder. Shortcuts look like this or this, and can be made by multiple Android file explorers including the apps here and here, but be sure to set the default app or command to Pydroid 3.
Rotates may hang or kill
On some devices, Pydroid 3 either kills the GUI silently or hangs altogether if the screen is rotated between portrait and landscape orientations while a tkinter GUI is running. Per user testing, rotates work fine on some recent Samsung devices that use the medium screen-zoom display setting, and possibly apply system updates. If your rotates don't work, try both remedies—or don't rotate.
Import paths
Some book examples require path settings for PP4E package imports. If needed, this setting can be forced by appending pathname strings to Python's sys.path list at the start of examples' code. Use the unzipped examples folder's path up to and including its Examples folder.
A mouse or stylus helps
Some examples have smaller controls and may warrant window resizes or moves; a stylus or mouse may make these interactions easier.
General caveats
Some examples exhibit cosmetic or operational rough edges that stem from Pydroid 3's tkinter implementation, and have to be tolerated as a price paid today for running PC-level GUIs on a phone.

Mergeall

Mergeall—an incremental-backup and change-propagation system—can be used to sync on-phone content to and from removable media. This program has both a command-line mode usable in apps like Termux, as well as a tkinter GUI usable in Pydroid 3. Pydroid 3 has a Terminal interface too, but it's too limited to recommend for Mergeall's command-line mode. The following summarizes the expanded coverage in this document. Note that Mergeall changes a destination folder by design; use it with care.

GUI Look and Feel

Mergeall's GUI in Pydroid 3 on Android looks like this:

Portrait
Start, browse, run, finish, and more
Landscape
Start, browse, run, finish, and more
Non-maximized/fullscreen
Landscape, portrait, and status

Orientation

Mergeall's GUI is usable in either landscape or portrait phone orientation, though portrait mode displays more run messages without scrolls, and landscape is less likely to truncate GUI content. Per usage notes ahead, rotating the screen after the GUI is running may not work on some devices.

Viewing Modes

Because Mergeall's GUI has no persistent popup windows and its exit verification can be skipped, it may render and work best using Pydroid 3's tkinter fullscreen and maximized viewing modes, the latter of which automatically resizes for fit on rotations. Select these modes by turning the first Tkinter switch off and the second on in Pydroid 3's Settings ⇨ System dialog before running the GUI, and press your phone's back button twice to exit the GUI. Mergeall's GUI can be used non-fullscreen and non-maximized viewing modes too (see the captures above), but they hold little usage advantage.

Running the Program

To run Mergeall on your Android device, follow these steps:

  1. Install the Pydroid 3 app if needed from the Play Store.
  2. Download Mergeall's source-code package from this page to any writable folder on your phone, and unzip (i.e. extract) it.
  3. Fetch the two custom files:

    And move them to the top level of your unzipped Mergeall source-code package, replacing the originals. Download by clicking "save" in the "Raw text" line of these links' pages, and search for "# ANDROID" to see code changes made if desired.

  4. Run Mergeall by opening its source-code package's file launch-mergeall-GUI.pyw in the Pydroid 3 app's editor, and pressing the editor's big yellow run button. Mergeall's GUI should appear, and work the same as it does on PCs.

Usage Notes

Also keep the following in mind when using Mergeall on Android:

Home-screen shortcuts
For quick two-tap access to Mergeall, make a home-screen shortcut (a.k.a. link) to its launch-mergeall-GUI.pyw source-code file. Shortcuts look like this or this, and can be made by multiple Android file explorers including the apps here and here, but be sure to set the default app or command to Pydroid 3.
Oreo+ only for all usage
Mergeall can be used on Android 8 (Oreo) and higher only, due to an Android timestamp bug in earlier versions. Mergeall will compare folders prior to Oreo, but the results are not meaningful because file timestamps are always copy time, and Mergeall updates will always fail due to timestamp-copy errors.
Rotates may hang or kill
On some devices, Pydroid 3 either kills the GUI silently or hangs altogether if the screen is rotated between portrait and landscape orientations while a tkinter GUI is running. Per user testing, rotates work fine on some recent Samsung devices that use the medium screen-zoom display setting, and possibly apply system updates. If your rotates don't work, try both remedies—or don't rotate.
Disabled widgets
The Mergeall GUI's "Help" and "Show logfile popup?" buttons are disabled on Android, because the Python webbrowser module they employ does not yet support this platform. Open Mergeall's user guide and logfiles outside the GUI instead.
Use FAT32 for Mac OS
Removable media used with Mergeall must be formatted as FAT32 for Mac OS interoperability, due to an existing exFAT timestamp bug.
Storage constraints
Mergeall can be used with both Termux command lines and Pydroid 3 GUIs. The full story on its storage constraints for Termux and Pydroid 3 is here and here. In brief, because both Termux and Pydroid 3 can update only their own app-specific folders on removable media, you must either choose which app will update removable-media content and nest it appropriately (see the next note), or locate your content anywhere in internal storage (e.g., /sdcard) where it can be updated by both apps.
GUI storage constraints
If you choose to use Mergeall in Pydroid 3 only, content that will only be read can be located anywhere. Content that will be updated can be located anywhere in internal storage (e.g., /sdcard), or nested in Pydroid 3's app-specific folder created manually on removable drives and named as follows (where the xs are your drive's Android ID):
/storage/xxxx-xxxx/Android/data/ru.iiec.pydroid3
Nesting caveat
Content nested in app-specific folders on removable media is automatically deleted when the owning app is uninstalled. This is especially dangerous in Mergeall, as the nested content may be all your on-phone data. Move nested content before uninstalls, or use internal storage instead.
Font constraints
Because some font types cause tkinter GUIs to crash silently in Pydroid 3, Mergeall's configuration file mergeall_configs.py was changed to disable text-area font customization by presetting it to None, which applies the system default. Experiment with font settings in this file as desired. In general, font families courier, times, and helvetica work (and monaco is courier and arial is helvetica), but most others crash the GUI, and italic and bold styles are ignored in font tuples but not strings.

Frigcal

Frigcal—a personal calendar program that uses portable iCalendar ICS files for event storage—can be used on Android to view and edit calendars which can also be used on other platforms, including Windows, Mac OS, and Linux PCs. Frigcal's animated launcher is not currently supported, but its main script can be run directly. This program runs only as a GUI.

GUI Look and Feel

Frigcal's GUI in Pydroid 3 on Android looks like this:

Orientation

Due to its size, Frigcal's GUI may work best in landscape (horizontal) phone orientation to maximize event label size. Per usage notes ahead, rotating the screen after the GUI is running may not work on some devices; where needed, rotate your phone to landscape orientation before running the program, and view more events by clicking a day's number or rotating to portrait where supported (more on event views ahead).

Viewing Modes

Pydroid 3's maximized viewing mode cannot be used for Frigcal if you wish to either save calendar changes or view Frigcal's persistent popup windows like month clones and images. Saves don't work in this mode because they happen in Frigcal only on exit requests; maximized mode hides the window-border exit button; Frigcal has no exit button of its own; and Pydroid 3 double-back exits do not run GUIs' exit handers. Persistent popups can't be viewed because the main window overlays and thus hides them.

Technically, Pydroid 3's double-back exits can be used in either maximized or non-maximized modes, but are the only Frigcal exit option in the former. Hence, maximized mode makes sense for Frigcal only when viewing but not changing calendars, and you should always use the window-border's upper-right "X" exit button instead of double-back exits in non-maximized mode unless you have no calendar changes to save.

Select or disable maximized mode before running the GUI with "Tkinter: maximize first window" in Pydroid 3's Settings ⇨ System dialog, and use a stylus or mouse for best window move/resize results in non-maximized mode; maximized mode automatically sizes for fit.

Running the Program

To run Frigcal on your Android device, follow these steps:

  1. Install the Pydroid 3 app if needed from the Play Store.
  2. Download Frigcal's source-code package from this page to any writable folder on your phone, and unzip (i.e. extract) it.
  3. Fetch the four custom files:

    And move them to the top level of your unzipped Frigcal source-code package, replacing the originals. The last of these is currently optional, as it applies only to the unusable animated launcher (see ahead). Download by clicking "save" in the "Raw text" line of these links' pages, and search for "# ANDROID" to see code changes made if desired.

  4. Run Frigcal by opening its source-code package's file frigcal.py in the Pydroid 3 app's editor, and pressing the editor's big yellow run button. Frigcal's GUI should appear, and work the same as it does on PCs.

Usage Notes

Also keep the following in mind when using Frigcal on Android:

Home-screen shortcuts
For quick two-tap access to Frigcal, make a home-screen shortcut (a.k.a. link) to its frigcal.py source-code file. Shortcuts look like this or this, and can be made by multiple Android file explorers including the apps here and here, but be sure to set the default app or command to Pydroid 3.
Rotates may hang or kill
On some devices, Pydroid 3 either kills the GUI silently or hangs altogether if the screen is rotated between portrait and landscape orientations while a tkinter GUI is running. Per user testing, rotates work fine on some recent Samsung devices that use the medium screen-zoom display setting, and possibly apply system updates. If your rotates don't work, try both remedies—or don't rotate.
Oreo+ only for updates
Frigcal can be used for updates on Android 8 (Oreo) and higher only, due to an Android timestamp bug in earlier versions that breaks calendar backups on saves. Prior to Oreo, calendars in Frigcal can be viewed, but cannot be changed and saved.
Maximize for view-only (only)
Pydroid 3's maximized mode is recommended when using Frigcal to view but not change calendars on your phone, because this mode provides the most screen space (especially if your navigation bar is hidden), and automatically resizes the window to refit the new aspect ratio after rotations. As noted earlier, this mode doesn't support calendar saves; use non-maximized mode to save, and manually resize to refit on rotations (shrinking before rotating may help with resizing).
Title dates
Just for Android, calendar month and year was added to month-window titles, so they are displayed in non-maximized mode for windows that are too small to retain their normal date+year labels.
Disabled widgets
The GUI's "?" help button does not work and is disabled on Android, because the Python webbrowser module it employs does not yet support this platform. Open Frigcal's user guide outside the GUI instead.
Truncated widgets
Some Frigcal widgets are obscured and unusable in portrait phone orientation; use landscape mode instead, and hide your phone's navigation bar for more GUI room (where possible). Conversely, option lists (e.g., color-scheme choices) too long for the display are truncated in landscape mode; rotate to portrait mode where supported to see more options.
Launcher not supported
Frigcal's animated launcher, file frigcal-launcher.pyw, displays its GUI but does not open the calendar in Pydroid 3, because it is not possible view the windows of a GUI program started by another GUI program. Run Frigcal's main script frigcal.py directly instead per above.
Start-ups are fast
Frigcal loads calendars quickly on start-up. In testing, a set of calendars with events spanning 15 years loads in 3 seconds on a Mac OS PC, and 4 to 5 seconds on an Android smartphone. The screen will be blank during loads due to the prior note's launcher issue, but the wait is short.
How to rightclick
Rightclicks are required to copy/paste events. In Pydroid 3, Frigcal rightclicks on events, days, or event-selection list items are triggered by either a subtle swipe with touch or stylus; a swipe with the mouse cursor while holding its left button; or a keyboard control + mouse click combo. Long presses and mouse rightclicks are not recognized. This may take some practice to perfect; zoom in if needed with pinch/spread gestures.
Viewing more events
Due to phone size constraints, the number of events that a day can display is limited, especially in landscape orientation. To view more events, double-tap a day's number to open its event-selection-list display. Like the GUI at large, this display supports both single clicks to open view/edit dialogs, as well as rightclicks (per the prior note) to open copy/cut dialogs. You can also view more events by rotating your device to portrait mode, but this fails on some phones while the GUI is running, and truncates event text.
Newlines may need help
The return key on some recent Samsung on-screen keyboards does not send a newline character to Frigcal in Pydroid 3. This matters for multiline descriptions in the event-edit dialog, but appears to be limited in scope. If the return key does not move the cursor to the next line on your device, either use a physical Bluetooth keyboard; use Samsung's handwriting-recognition input, whose return key works correctly; or install and use an alternative keyboard whose return key works properly.

For the latter option, both Google Gboard and Hacker's Keyboard on-screen keyboards correctly send newlines to Frigcal on return-key presses. The second of these also provides access to PyEdit menu shortcuts, and can be opened on demand for PyPhoto commands.

Copy/paste may need help
Android-style copy and paste via longpresses is not available in tkinter GUIs run in Pydroid 3. To cut and paste text in Frigcal's text-input fields, highlight with touch, then use the PC-like key combinations Ctrl+c to copy and Ctrl-v to paste in keyboards that support these. You'll find support for these keys in both Bluetooth keyboards, and alternative on-screen keyboards like Hacker's Keyboard.
Storage constraints
Due to Android and Pydroid 3 permission constraints, view-only calendars can be stored anywhere on your device, but updatable calendars must be in a folder that either is located anywhere in internal storage (e.g., /sdcard), or is nested in Pydroid 3's app-specific folder on removable-media. To nest on removable media, locate your calendars folder in the following manually created folder on your drive (the xs are your drive's Android ID):
/storage/xxxx-xxxx/Android/data/ru.iiec.pydroid3

Updates to any other removable-storage folders will fail, like the sequence here, here, and here. Note that uninstalling an app deletes its app-specific folders, including any user content there.

Calendar transfers
To transfer calendars between your phone and PCs, simply copy your Frigcal calendar folder to or from your phone. Files in this folder work in a variety of calendar programs, including Frigcal on PCs. Be sure to set your calendar-folder path—icspath in the Frigcal configurations file frigcal_configs.py—to the folder you'll use on the phone for calendars shared with PCs.
Optional Android-changes calendar
You may find it useful to dedicate a calendar file to events edited on your Android device, and select this file in the GUI whenever creating new events on your phone. This way, Android changes can be easily transferred to your PCs, and won't interfere with calendar edits made elsewhere.

To make a new calendar file for Android use, run the Frigcal source-code package's makenewcalendar.py on either your PC or phone. On your phone, run this script by opening it in Pydroid 3's IDE like this and pressing the yellow run button as usual, and enter a calendar name like this. Once created, choose the new calendar in the GUI like this You can also run the maker script in the app's Terminal interface, but it's a lot of typing in a primitive shell.

For more on Frigcal calendar files in general, see its user guide's coverage. You can also sync shared calendar files back and forth between PCs and phones, but a dedicated Android calendar supports changes more freely (though you should take care to avoid overwriting your Android calendar by to-phone content syncs).

Optional Pillow install
Frigcal's month-images option requires the Pillow third-party library to be installed in Pydroid 3 for some image types, though not for the shipped default images, and not for PNGs and GIFs in general. Install Pillow if needed by running the command line pip install Pillow in Pydroid 3's Terminal window opened from its main menu. More details here.
Font constraints
Because some font types cause tkinter GUIs to crash silently in Pydroid 3, Frigcal's configuration file frigcal_configs.py was changed to disable most user font customizations by presetting them to None, which applies system defaults. Experiment with Frigcal font settings in this file as desired. In general, font families courier, times, and helvetica work (and monaco is courier and arial is helvetica), but most others crash the GUI, and italic and bold styles are ignored in font tuples but not strings.
Other configurations
Also in frigcal_configs.py: the font of Frigcal's event edit/view dialog was preset for readability (system defaults are small); the initial size of this dialog was preset for use on a phone (though it's resizable in the GUI); and click mode was changed from double-click mouse to single-click touch to minimize keyboard popups at the expense of inline summary edits (see the user guide for more on the difference). Tailor any of these for your usage, and see frigcal_configs_base.py in your source-code package for the full set of user-configurable options.

PyEdit

PyEdit—a general-purpose text editor and Python code launcher—can be used on Android to both edit arbitrary text files and run Python code being edited in the GUI. This program runs only as a GUI.

GUI Look and Feel

PyEdit's GUI in Pydroid 3 on Android looks like:

Orientation

Due to phone size constraints, PyEdit's GUI may work best in landscape (horizontal) phone orientation, to avoid horizontal slides and toolbar truncation. Per usage notes ahead, rotating the screen after the GUI is running may not work on some devices; where needed and desired, rotate your phone to landscape orientation before running the program.

Viewing Modes

Because it opens many persistent popup windows and must verify program closes, PyEdit's GUI is better used without Pydroid 3's tkinter maximized viewing mode. This mode automatically resizes for fit, but it overlays persistent popups, and its lack of a window-border exit button encourages silent double-click exits that may discard changes. Maximized mode may be best used in PyEdit only to view, but not change, a single document. Select or disable this mode before running the GUI with "Tkinter: maximize first window" in Pydroid 3's Settings ⇨ System dialog, and use a stylus or mouse for best window move/resize results in non-maximized mode.

Whether you use maximized mode or not, do not exit the GUI with a Pydroid 3 double-back click, or unsaved changes may be lost. Instead, be sure to exit the GUI only by using its Quit toolbar button or File ⇨ Quit menu option available in all modes, or by pressing its window-border's "X" exit button available in non-maximized mode. All three techniques offer you a chance to save edits before the GUI closes.

Running the Program

To run PyEdit on your Android device, follow these steps:

  1. Install the Pydroid 3 app if needed from the Play Store.
  2. Download PyEdit's source-code package from this page to any writable folder on your phone, and unzip (i.e. extract) it.
  3. Fetch the two custom files:

    And move them to the top level of your unzipped PyEdit source-code package, replacing the originals. Download by clicking "save" in the "Raw text" line of these links' pages, and search for "# ANDROID" to see code changes made if desired.

  4. Run PyEdit by opening its source-code package's file textEditor.py in the Pydroid 3 app's editor, and pressing the editor's big yellow run button. PyEdit's GUI should appear, and work the same as it does on PCs.

Usage Notes

Also keep the following in mind when using PyEdit on Android:

Home-screen shortcuts
For quick two-tap access to PyEdit, make a home-screen shortcut (a.k.a. link) to its textEditor.py source-code file. Shortcuts look like this or this, and can be made by multiple Android file explorers including the apps here and here, but be sure to set the default app or command to Pydroid 3.
Rotates may hang or kill
On some devices, Pydroid 3 either kills the GUI silently or hangs altogether if the screen is rotated between portrait and landscape orientations while a tkinter GUI is running. Per user testing, rotates work fine on some recent Samsung devices that use the medium screen-zoom display setting, and possibly apply system updates. If your rotates don't work, try both remedies—or don't rotate.
Disabled widgets
The GUI's "Help" dialog and most of its resources work well, but the help dialog's "User Guide" is disabled on Android because the Python webbrowser module it employs does not yet support this platform. Open PyEdit's user guide outside the GUI instead.
Truncated widgets
Some PyEdit toolbar widgets are obscured and unusable in portrait phone orientation. Use landscape mode instead (where helpful); rotate as needed to see more widgets (where supported); and hide your phone's navigation bar for more GUI room (where possible).
Toolbar symbols
PyEdit was changed to use the same toolbar symbols as the Mac OS PC, because those used for Linux rendered too small to be usable on Android. Even so, a stylus or mouse helps, and menus may be more accessible on Android in general.
Cosmetic caveats
Pydroid 3 always botches the Unicode main/popup character of window titles in non-maximized mode, and occasionally munges Unicode characters in the toolbar too. There is no workaround, short of dropping the characters altogether; for now, please mind the gaps.
Keyboard shortcuts
PyEdit's menu options and their keyboard shortcuts are always available regardless of screen size and orientation. Use menu pulldowns or access menu shortcuts with a Bluetooth keyboard or an alternative on-screen keyboard with control keys (see the next item) if toolbar buttons are not accessible due to truncation. Caveat: Pydroid 3's tkinter does not seem to recognize the Alt key for menu shortcuts, in keyboards that support this key; use pulldown-menu or toolbar-button equivalents instead.
Newlines may need help
The return key on some recent Samsung on-screen keyboards does not send a newline character to PyEdit in Pydroid 3. This is crucial to editing multiline text in PyEdit, but appears to be limited in scope. If the return key does not move the cursor to the next line on your device, either use a physical Bluetooth keyboard; use Samsung's handwriting-recognition input, whose return key works correctly; or install and use an alternative keyboard whose return key works properly.

For the latter option, both Google Gboard and Hacker's Keyboard on-screen keyboards correctly send newlines to PyEdit on return-key presses. The second of these also has a full set of control and function keys useful for PyEdit menu shortcuts, and an on-demand-open feature useful for PyGadgets' PyPhoto operation (see ahead).

Copy/paste may need help
Android-style copy and paste via longpresses is not available in tkinter GUIs run in Pydroid 3. To cut and paste text in PyEdit's edit windows and other text-input fields, highlight with touch, then either use Edit menu options in edit windows to copy and paste, or use the PC-like key combinations Ctrl+c to copy and Ctrl-v to paste in keyboards that support these. You'll find support for these keys in both Bluetooth keyboards, and alternative on-screen keyboards like Hacker's Keyboard.
Weird cursor rectangles (or not)
In limited contexts, Pydroid 3's tkinter may draw a large rectangle around the cursor in PyEdit's text input fields. It's not clear if this is intended visibility feature or anomaly, and has been observed only when using a Bluetooth keyboard on Samsung Galaxy Note9 devices running Android Oreo (it does not appear for earlier Androids or on-screen keyboards). If the rectangle appears for you, turning it on and off is easy: to disable, click your phone's back button once and tap the text anywhere on the screen before reusing your keyboard; to enable, click your phone's back button once and start reusing your keyboard without a screen tap. Strange (and undocumented, as far as a web search can tell) but true.
Storage constraints
In Pydroid 3, PyEdit can both save (and auto-save) files anywhere in internal storage (e.g., /sdcard). On a removable drive, it can save (and auto-save) files only in the Pydroid 3 app-specific folder, which is the drive's manually created folder named as follows (the xs mean your drive's Android ID):
/storage/xxxx-xxxx/Android/data/ru.iiec.pydroid3

Files can be viewed anywhere on your device, but saves are limited this way by Android and Pydroid 3 permission constraints. Note that uninstalling an app deletes its app-specific folders, including any user content there.

Grep must use threads
PyEdit's configuration file textConfig.py was changed to use threads instead of the multiprocessing module for parallel greps, because the latter fails on Android due to that platform's lack of required semaphore support. Threads work well in testing so far, though they cannot leverage multiple CPU cores (a factor perhaps more important on PCs than phones).
Font constraints
Because some font types cause tkinter GUIs to crash silently in Pydroid 3, PyEdit's configuration file textConfig.py was also changed to disable most user font customizations by adding triple quotes above and below custom settings. The default fonts pick list was also changed to remove crashing fonts, and a text-font preset was coded for readability (the system default is likely too small for some readers to use).

Experiment with PyEdit font settings in this file as desired. In general, font families courier, times, and helvetica work (and monaco is courier and arial is helvetica), but most others crash the GUI, and italic and bold styles are ignored in font tuples but not strings.

PyGadgets

PyGadgets—a GUI utility "toy box"—is partly operational on Android. Although the program's launcher itself does not run, the programs launched, including a calculator, clock, photo viewer, and simple game, can be run directly on this platform in Pydroid 3. These programs run only as GUIs.

GUI Look and Feel

On Android in Pydroid 3, the directly runnable utilities of PyGadgets look like:

Orientation

All these GUIs work in either portrait or landscape orientation; experiment to find the best rotation for each, but note that rotating the screen after a GUI is running may not work on some devices per usage notes ahead.

Viewing Modes

PyToe tends to render and work best in Pydroid 3's tkinter maximized viewing mode for automatic fill and resizing; select this mode before running the GUI with "Tkinter: maximize first window" in Pydroid 3's Settings ⇨ System dialog, and press your phone's back button twice to exit the GUI in this mode. PyCalc and PyPhoto both open persistent popup windows that can be easily hidden in maximized mode; clear maximized mode for these GUIs, and exit by clicking the GUI's or window's exit button. PyClock works in any viewing mode.

Running the Programs

To run PyGadgets utilities on your Android device, follow these steps:

  1. Install the Pydroid 3 app if needed from the Play Store.
  2. Download PyGadgets' source-code package from this page to any writable folder on your phone, and unzip (i.e. extract) it.
  3. Fetch the three custom files:

    And move the first two to the top level of your unzipped PyGadgets source-code package, and the last to the _PyToe/TicTacToe subfolder in the unzipped package, replacing the originals. The first two files are currently optional, as they apply only to the unusable launcher (see ahead).

  4. To avoid font-related crashes in the gadgets' help dialogs, also fetch custom file:

    And copy it to all four gadget-script folders listed in the next step. For all custom files, download by clicking "save" in the "Raw text" line of these links' pages, and search for "# ANDROID" to see code changes made if desired.

  5. Run PyGadgets utilities by opening any of the following source-code package's files in the Pydroid 3 app's editor:
    _PyCalc/Calculator/calculator.py
    _PyClock/Clock/clock.py
    _PyPhoto/PIL/pyphoto.py
    _PyToe/TicTacToe
    

    Once a file is open, press the editor's big yellow run button to run the program, which will work the same as it does on PCs.

Usage Notes

Also keep the following in mind when using PyGadgets utilities on Android:

Home-screen shortcuts
For quick two-tap access to any PyGadgets utility, make a home-screen shortcut (a.k.a. link) to its source-code file (e.g., to calculator.py in folder _PyClock/Clock for PyCalc). Shortcuts look like this or this, and can be made by multiple Android file explorers including the apps here and here, but be sure to set the default app or command to Pydroid 3.
Rotates may hang or kill
On some devices, Pydroid 3 either kills the GUI silently or hangs altogether if the screen is rotated between portrait and landscape orientations while a tkinter GUI is running. Per user testing, rotates work fine on some recent Samsung devices that use the medium screen-zoom display setting, and possibly apply system updates. If your rotates don't work, try both remedies—or don't rotate.
Launcher not supported
PyGadgets' utility launcher, file PyGadgets.py, displays its GUI but its buttons do not work in Pydroid 3, because GUI programs spawned by GUI programs run but do not display their windows. Run gadgets directly instead per above.
PyCalc: buttons stay "on"
Due to an unknown flaw in Pydroid 3's tkinter, the calculator buttons in PyCalc retain their pressed appearance until the next GUI event. The GUI and its calculations work fine anyhow, and this might even be classified as a history feature, but it differs from PyCalc's PC and intended behavior. This remains a TBD; a fix may entail a forced GUI update call, or changing the code to use labels instead of buttons as formerly done for Mac OS at the expense of press feedback.
PyPhoto: install Pillow
PyPhoto requires the Pillow third-party library to be installed in Pydroid 3: install it by running the command line pip install Pillow in Pydroid 3's Terminal window opened from its main menu.
PyPhoto: keypresses need help
PyPhoto's operation relies heavily on keyboard keypresses that are not normally available in touch. The on-screen keyboard doesn't appear in PyPhoto because its GUI has no input field to tap, and most preinstalled keyboards (including Samsung's) won't open any other way. Luckily, there are three workarounds for this issue.

To perform keypresses in PyPhoto, either use a physical Bluetooth keyboard; click the GUI's Help button and press the text content of its help dialog to force the on-screen keyboard to appear (a trick to be sure, but it works); or install the Hacker's Keyboard app on your phone and enable its permanent-notification option, which allows you to pop up its on-screen keyboard on demand by clicking the app's entry in Android's notifications pulldown. Bonus: Hacker's Keyboard also provides arrow keys which scroll PyPhoto indexes and images, and enables newlines and menu shortcuts in PyEdit.

PyPhoto: thumbnail storage
PyPhoto must be able to store thumbnail cache files when they are updated. These files are written in the opened images folder, and in Pydroid 3 can be saved either anywhere in internal storage (e.g., /sdcard), or on removable drives only in the following manually created Pydroid 3 app-specific folder (in which xs stand for your drive's Android ID):
/storage/xxxx-xxxx/Android/data/ru.iiec.pydroid3

Cache files can be viewed anywhere on your device, but saves are limited by Android and Pydroid 3 permission constraints. Note that uninstalling an app deletes its app-specific folders, including any user content there.

PyPhoto: FAT32 updates
PyPhoto may update its per-folder cache files unexpectedly, if you are using a FAT32 SD card for on-phone storage, and daylight savings time or time zone differs from that used when thumbnails were saved. This is a one-time update. Content managed by Mergeall on removable drives must be stored using FAT32 for Mac OS content interoperability (see Mergeall usage notes).
PyPhoto: no TIFFs
PyPhoto does not support TIFF images in Pydroid 3, because the Pillow library it uses for image processing does not either. These photos work on PC platforms, but have rendering issues on some Mac OS versions; in PyPhoto, they appear as "?" items in thumbnail indexes and do not open when clicked.
Why helpmessage.py
The help dialogs of all PyGadgets' utility programs crash without the helpmessage.py copies noted earlier, because this file's original code tries to set font type to system which fails (see the next note).
Font constraints
Because some font types cause tkinter GUIs to crash silently in Pydroid 3, PyGadgets' configuration file PyGadgets_configs.py was changed to disable user font customizations by adding triple quotes above and below custom settings. At present, this file is unused, because it applies only to gadgets when they are launched from the currently unusable launcher. Fonts in gadgets run directly are taken from command-line arguments or else hardcoded defaults.

If the launcher ever comes online, or you wish to specify fonts for gadgets run directly, be careful to use only supported font names. In general, font families courier, times, and helvetica work (and monaco is courier and arial is helvetica), but most others crash the GUI, and italic and bold styles are ignored in font tuples but not strings.

PyMailGUI

Not supported on Android (yet?)

PyMailGUI—a full-featured POP/SMTP email client GUI—has not yet been ported to Android, because its account launcher is not operational. In short, GUI programs spawned by other GUI programs in the Pydroid 3 app run but do not display their windows. This same limitation cripples launchers in Frigcal and PyGadgets above, but their launched programs can still be run directly with a minor loss in functionality. In PyMailGUI, though, this issue is fatal, because it is impossible to open email accounts as freestanding programs without the launcher.

Though its exact causes are unknown, this constraint may be a limitation inherent in the Pydroid 3 approach: a spawned Linux program may have no notion of running in that app's IDE, and this may be the sole source of tkinter support (a special import statement form, for example, is required to enable GUIs at all, and tkinter GUIs fail in Pydroid 3's own Terminal). Barring a workaround for the GUI-spawn issue, PyMailGUI awaits either a major rewrite to open accounts as in-process tkinter Toplevel windows, or an alternative and convenient method for opening email accounts' windows without a launcher.



[Python Logo] News Blog Apps GotoTop Mergeall Comment ©M.Lutz