I am trying to write an app in python to control a motor using serial. This all works in a CLI situation fine and is generally stable. but I was wondering how simple it was to add a GUI on top of this code base?
I assume there will be more code, but is there a simple way of detecting something like GTK, so it only applied the code when GTK was present?
Also, GUI creation in Python in general: is it best to keep as little GUI specifics out of the code and use something like GTK’s XML based approach (using gtk.glade.XML() function)? Are there other GUI toolkits that have a similar approach to the Glade / XML / “Explode in Code” approach?
Thanks for any advice.
Andy
First, break your app into 3 separate modules.
The actual work:
foo_core.py.A CLI module that imports
foo_core. Call itfoo_cli.py.A GUI module that imports
foo_core. Call itfoo_gui.pyw.The
foo_climodule looks like this.The
foo_guimodule can look like this.That’s generally sufficient. People can be trusted to decide for themselves if they want CLI or GUI.
If you want to confuse people, you can write a
foo.pyscript that does something like the following.