pythoncdebuggingtkinterintegration

Calculator GUI Prints Only "2" Regardless of Calculation – C Backend and Python (Tkinter) Frontend


Hello everyone,

I'm new to programming and recently built a calculator application with a backend written in C and a frontend using Python's Tkinter. When I run main.py, the GUI appears without any issues, but no matter what calculations I perform, the output is always "2." I'm unsure why this happens.

I’ve provided the GitHub link to my project below. Any insights into why this might be occurring or guidance on fixing it would be greatly appreciated. Thank you for your help!

github link : github link

I expected the calculator to perform arithmetic operations correctly, but it keeps outputting "2" regardless of the input


Solution

  • Debug mode can help you. In function perform_operation send true values "a" and "b", but your problem in string:

            return operations[operation](ctypes.c_double(a), ctypes.c_double(b))
    

    add next code:

    lib = ctypes.CDLL(os.path.join(".", "libcalculations.so"))
    lib.add.restype = ctypes.c_double
    lib.subtract.restype = ctypes.c_double
    lib.multiply.restype = ctypes.c_double
    lib.divide.restype = ctypes.c_double