you can see how having the buttons in list is big win here we can use for loop to look at each button in turn if the clicked point turns out to be in one of the buttonsthe label of that button is returnedproviding an exit from the otherwise infinite while loop the last step is to update the display of the calculator according to which button was clicked this is accomplished in processkey basicallythis is multi-way decision that checks the key label and takes the appropriate action digit or operator is simply appended to the display if key contains the label of the buttonand text contains the current contents of the displaythe appropriate line of code looks like thisself display settext(text+keythe clear key blanks the display self display settext(""the backspace strips off one character self display settext(text[:- ]finallythe equal key causes the expression in the display to be evaluated and the result displayed tryresult eval(textexceptresult 'errorself display settext(str(result)the try-except here is necessary to catch run-time errors caused by entries that are not legal python expressions if an error occursthe calculator will display error rather than causing the program to crash here is the complete programcalc pyw - four function calculator using python arithmetic illustrates use of objects and lists to build simple gui from graphics import from button import button class calculatorthis class implements simple calculator gui def __init__(self)create the window for the calculator win graphwin("calculator"win setcoords( , , , win setbackground("slategray"