[Solved] Questions about lambda and eval in relation to some Python calculator GUI code [closed]


Assigned variables are just that. Assigned by the coder. I have variable_name = object. If there are Tkinter specific variables being used at some point it is most likely a PSEUDO-CONSTANT that is used in arguments within the methods of tkinter. You should never try to change predefined variables that are part of the tkinter library.

The pack() portion is just placing the Frame object in the root window to be viewed by the user.

pack() is part of a set of geometry managers used to place objects on the GUI such as the frame or a text box or an entry field and many more. The details of pack() or any geometry manager are well documented in tkinter docs.

Lambda statements are also documented extensively but simply they anonymous functions. This means you do not need to assign this function a name. They are also one line functions. Their use is common in python and tkinter.

As for where the calculation is actually happening is the eval operation.
This is the code being used to perform the actual calculation.

def calc(self, display):
    try:
        display.set(eval(display.get()))
    except:
        display.set("ERROR")

This method specifically is what is performing the calculation:

eval(display.get())

As eval is not commonly know for newer programmers or ones new to python I can see how you were not sure where this might be calculated however the function name should be a clue as calc is short for calculation or calculate.

1

solved Questions about lambda and eval in relation to some Python calculator GUI code [closed]