parsesevaluatesand returns the result of python expression represented as string exec runs an arbitrary python statement represented as stringand has no return value both accept optional dictionaries to be used as global and local namespaces for assigning and evaluating names used in the code strings in the calculatorself names becomes symbol table for running calculator expressions related python functioncompilecan be used to precompile code strings to code objects before passing them to eval and exec (use it if you need to run the same string many timesby defaulta code string' namespace defaults to the caller' namespaces if we didn' pass in dictionaries herethe strings would run in the eval method' namespace since the method' local namespace goes away after the method call returnsthere would be no way to retain names assigned in the string notice the use of nested exception handlers in the class' eval method it first assumes the string is an expression and tries the built-in eval function if that fails because of syntax errorit tries evaluating the string as statement using exec finallyif both attempts failit reports an error in the string ( syntax errorundefined nameand so onstatements and invalid expressions might be parsed twicebut the overhead doesn' matter hereand you can' tell whether string is an expression or statement without parsing it manually note that the "evalbutton evaluates expressionsbut sets python variables by running an assignment statement variable names are combinations of the letter keys "abcd(or any name typed directlythey are assigned and evaluated in dictionary used to represent the calculator' namespace and retained for the session extending and attaching clients that reuse this calculator are as simple as the calculator itself like most classbased tkinter guisthis one can be extended in subclasses--example - customizes the simple calculator' constructor to add extra widgets example - pp \lang\calculator\calc ext py from tkinter import from calc import calcgui class inner(calcgui)def __init__(self)calcgui __init__(selflabel(selftext='calc subclass'pack(button(selftext='quit'command=self quitpack(extend gui add after top implied pycalca calculator program/object