[Python-ideas] Yielding from the command line
Terry Reedy
tjreedy at udel.edu
Thu Sep 11 20:19:52 CEST 2014
On 9/11/2014 11:31 AM, Andrew Barnert wrote:
> If it also came with builtin wrappers to embed all the popular GUI
> event loops in asyncio-style coroutines (or, hell, I'd be happy with
> just Tkinter, or the native Cocoa runloop) and automatically toss
> them into the main event loop, that could make interactively
> experimenting with GUIs as easy as it is in Smalltalk (well, except
> for not being able to turn your experiment into a persistent image).
One can interactactively experiment with the visual aspects of tkinter
now and at least some dynamic behavior. At console interpreter or Idle
(prompts deleted, only fully tested with Idle)
import tkinter as tk
root = tk.Tk() # empty window displayed
def click(): print('clicked')
b = tk.Button(root, text='click', command=click)
b.pack() #default button default packed
# click button -- button visibly changes,'clicked' is printed on shell)
# experiment with Button options that affect appearance
b.destroy() # button removed
I presume full behavior requires the call to root.mainloop(). This has
two problems for continued interaction. First, the call blocks until
the window is closed, making further entry impossible through normal
means. If that were solved with a 'noblock' option, there would still
be the problem of getting shell input to a callback that could, on
demand, execute to code to modify the tk app. The solution would have
to be different for the console interpreter, there tkinter is running in
the same process and Idle, where tkinter is running is a separate process.
It would probably be easier to create an event handler that would pop up
a separate text window and exec the code entered.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list