Feasibility of console based (non-Gui) Tkinter app which can accept keypresses?
rosuav at gmail.com
Wed Jul 11 13:41:38 EDT 2018
On Thu, Jul 12, 2018 at 12:09 AM, jkn <jkn_gg at nicorp.f9.co.uk> wrote:
> Hi All
> 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.
ISTM you want to have a variant Controller as well, to allow a
completely different way of managing the display. The easiest and
cleanest UI is probably a line-based console input command system,
where the user would type something and hit enter, and you receive
that using input(). That also plays nicely with input redirection,
allowing you to control your program from another program.
More information about the Python-list