Application console for Tkinter program?
Terry Reedy
tjreedy at udel.edu
Sun Mar 6 07:12:43 EST 2016
On 3/6/2016 4:23 AM, Christian Gollwitzer wrote:
> Am 05.03.16 um 22:16 schrieb Terry Reedy:
>> Not now. A console is a REPL + text display to read from and print to.
>> The actual IDLE REPL is PyShell.ModifiedInterpreter, which subclasses
>> stdlib code.InteractiveInterpreter. Most of the additions are for
>> interacting with the subprocess that runs user code. You should start
>> instead with the base class.
>>
>> The Shell text display is a subclass of a subclass of a class that
>> contains a subclass of Toplevel with the complete IDLE Menu and a Text
>> widget wrapper. Again, this is too much baggage for an application
>> console.
>>
>> The idlelib ColorDelegator syntax highlighter can be reused with a Text
>> instance. See turtledemo.__main__ for an example. I don't know if (or
>> how) IDLE's autocompletion modules could be reused in their current
>> state. I believe Shell's history 'list' consists of the statements in
>> the Text instance prefixed by the '>>> ' prompt.
>
> Thanks! I'll try to browse my way through the source code, these details
> help a lot. I still haven't understood the difference between exec() and
> eval(). I understand that for statements you want to exec them, for
> expressions you eval it and print the result. When the user has entered
> code, how does the REPL know if it should be eval'ed or exec'ed? I
> assume that you don't try to parse the Python code manually to find this
> out? Or you try to eval(), and if it doesn't compile, you exec()?
Python expressions are also statements. Python REPLs exec statements.
But to make Read-Exec-Print work like traditional Read-Eval-Print,
Python, in interactive mode, echos the value of expression statements
(and assign it to _ for later reuse). So '2 + 2' echos 4 in REPL, or at
least in the console and IDLE, '2 + 2' is useless in a program run in
batch mode.
--
Terry Jan Reedy
More information about the Python-list
mailing list