Feasibility of console based (non-Gui) Tkinter app which can accept keypresses?
jkn_gg at nicorp.f9.co.uk
Wed Jul 11 10:09:17 EDT 2018
This is more of a Tkinter question rather than a python one, I think, but
I have a Python simulator program with a Model-View_Controller architecture. I
have written the View part using Tkinter in the first instance; later I plan
to use Qt.
However I also want to be able to offer an alternative of a console-only
operation. So I have a variant View with the beginnings of this.
Naturally I want to keep this as similar as possible to my Tkinter-based view. I
had thought that I had seen a guide somewhere to using Tk/Tkinter in a non-GUI
form. I don't seem to be able to track this down now, but I have at least been
successful in hiding ('withdrawing') the main Frame, and running a main loop.
The bit which I am now stumbling on is trying to bind key events to my view,
and I am wondering if this actually makes any sense. In the absence of a GUI I
want to accept keypresses to control the simulation. But in a console app I will
have no visible or in focus window, and therefore at what level would any
keys be bound? Not at the widget level, nor the frame, and I am not sure if the
the root makes sense either.
So I am looking for confirmation of this, and/or whether there is any way of
running a Tkinter application in 'console' mode, running a main loop and
both outputting data and accepting, and acting on, key presses.
More information about the Python-list