def onoperator(selfchar)self eval shiftopnd(self text get()self eval shiftoptr(charself text set(self eval topopnd()self erase push opnd on left eval exprs to leftpush optrshow opnd|result erased on next opnd|'(def onmakecmdline(self)new toplevel(new top-level window new title('pycalc command line'arbitrary python code frm frame(newtoponly the entry expands label(frmleft''pack(expand=novar stringvar(ent entry(frmleftvarwidth= onbutton (lambdaself oncmdline(varent)onreturn (lambda eventself oncmdline(varent)button(frmright'run'onbuttonpack(expand=noent bind(''onreturnvar set(self text get()def oncmdline(selfvarent)eval cmdline pop-up input tryvalue self eval runstring(var get()var set('okay'if value !nonerun in eval namespace dict self text set(valueexpression or statement self erase var set('okay ='valueexceptresult in calc field var set('error'status in pop-up field ent icursor(endinsert point after text ent select_range( endselect msg so next key deletes def onkeyboard(selfevent)pressed event char on keyboard press event if pressed !''pretend button was pressed if pressed in self operatorsself onoperator(pressedelsefor row in self operandsif pressed in rowself onoperand(pressedbreak else edrop 'llif pressed ='self onoperand(pressedcan start opnd if pressed in 'ee' no +/self text set(self text get()+pressedcan'tno erase elif pressed ='\ 'self oneval(enter key=eval elif pressed ='self onclear(spacebar=clear elif pressed ='\ 'self text set(self text get()[:- ]backspace text and language