On 07/11/18 07:09, jkn wrote:
Hi All
This is more of a Tkinter question rather than a python one, I think, but
anyway...
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.
Thanks
J^n
I think the general answer is no, but beyond that, it may be worth
considering switching from an MVC architecture to a simpler
frontend-backend, especially if you intend to add a third interface (Qt):
MVC w/Tk, console, Qt:
Seven conceptual modules (three controllers, three views, one model)
Two abstraction layers (controller<->model, model<->view)
Frontend-backend w/Tk, console, Qt:
Four conceptual modules (three frontends, one backend)
One abstraction layer (frontend<->backend)
-Jim
--
https://mail.python.org/mailman/listinfo/python-list