Repository: ipython/ipython

Issue:
Specifying --gui=tk at the command line
I'd like to be able to specify `--gui=tk` at the command line.

I'm trying to embed a kernel into my Tkinter app following [the similar Qt example](https://github.com/ipython/ipython/blob/master/examples/lib/internal_ipkernel.py). When I use `kernel.initialise(['python', '--gui=tk'])` I get the error message:

```
CRITICAL | The 'gui' trait of an IPKernelApp instance must be any of ('qt', 'wx', 'gtk', 'glut', 'pyglet', 'osx') or None, but a value of 'tk' <class 'str'> was specified.
```

I can't use `--pylab=tk` because I don't want the kernel to try to initialise Matplotlib.



Discussion:

Resolving patch:
diff --git a/IPython/core/shellapp.py b/IPython/core/shellapp.py
--- a/IPython/core/shellapp.py
+++ b/IPython/core/shellapp.py
@@ -36,11 +36,14 @@
 from IPython.utils.traitlets import (
     Unicode, Instance, List, Bool, CaselessStrEnum, Dict
 )
+from IPython.lib.inputhook import guis
 
 #-----------------------------------------------------------------------------
 # Aliases and Flags
 #-----------------------------------------------------------------------------
 
+gui_keys = tuple(sorted([ key for key in guis if key is not None ]))
+
 backend_keys = sorted(pylabtools.backends.keys())
 backend_keys.insert(0, 'auto')
 
@@ -175,8 +178,8 @@ def _extra_extension_changed(self, name, old, new):
     module_to_run = Unicode('', config=True,
         help="Run the module as a script."
     )
-    gui = CaselessStrEnum(('qt', 'wx', 'gtk', 'glut', 'pyglet', 'osx'), config=True,
-        help="Enable GUI event loop integration ('qt', 'wx', 'gtk', 'glut', 'pyglet', 'osx')."
+    gui = CaselessStrEnum(gui_keys, config=True,
+        help="Enable GUI event loop integration with any of {0}.".format(gui_keys)
     )
     matplotlib = CaselessStrEnum(backend_keys,
         config=True,
diff --git a/IPython/lib/inputhook.py b/IPython/lib/inputhook.py
--- a/IPython/lib/inputhook.py
+++ b/IPython/lib/inputhook.py
@@ -481,6 +481,19 @@ def current_gui(self):
 current_gui = inputhook_manager.current_gui
 clear_app_refs = inputhook_manager.clear_app_refs
 
+guis = {None: clear_inputhook,
+        GUI_NONE: clear_inputhook,
+        GUI_OSX: lambda app=False: None,
+        GUI_TK: enable_tk,
+        GUI_GTK: enable_gtk,
+        GUI_WX: enable_wx,
+        GUI_QT: enable_qt4, # qt3 not supported
+        GUI_QT4: enable_qt4,
+        GUI_GLUT: enable_glut,
+        GUI_PYGLET: enable_pyglet,
+        GUI_GTK3: enable_gtk3,
+}
+
 
 # Convenience function to switch amongst them
 def enable_gui(gui=None, app=None):
@@ -507,18 +520,6 @@ def enable_gui(gui=None, app=None):
     PyOS_InputHook wrapper object or the GUI toolkit app created, if there was
     one.
     """
-    guis = {None: clear_inputhook,
-            GUI_NONE: clear_inputhook,
-            GUI_OSX: lambda app=False: None,
-            GUI_TK: enable_tk,
-            GUI_GTK: enable_gtk,
-            GUI_WX: enable_wx,
-            GUI_QT: enable_qt4, # qt3 not supported
-            GUI_QT4: enable_qt4,
-            GUI_GLUT: enable_glut,
-            GUI_PYGLET: enable_pyglet,
-            GUI_GTK3: enable_gtk3,
-            }
     try:
         gui_hook = guis[gui]
     except KeyError:


Test patch: