I recently wrote a simple fraction calculator that has add, subtract, multiply, divide, and reduce methods. Everything works fine, but I want to add a GUI to it. I have messed around with tkinter a little bit, but I'm not sure how I can use it to create a graphical calculator application. Here is the code I have written so far:

from fractions import gcd def mult(n1, d1, n2, d2): num = n1*n2 den = d1*d2 return (num, den) def div(n1, d1, n2, d2): num = n1*d2 den = d1*n2 return (num,den) def add(n1, d1, n2, d2): if d1 == d2: return (n1+n2, d1) else: n1, n2 = n1*d2, n2*d1 d = d1*d2 return (n1+n2, d) def sub(n1, d1, n2, d2): if d1 == d2: return (n1-n2, d1) else: n1, n2 = n1*d2, n2*d1 d = d1*d2 return (n1-n2, d) def reduce(num, den): divisor = gcd(num, den) if divisor <= 1: return None else: return (num/divisor, den/divisor) def showSol(sol): redSol = reduce(sol[0], sol[1]) if redSol == None: print("%d/%d" % (sol[0], sol[1])) else: print("%d/%d" % (redSol[0], redSol[1])) def main(): op = input("Operation (+, -, *, /) > ") n1, d1 = eval(input("Enter first fraction (num, den) > ")) n2, d2 = eval(input("Enter second fraction (num, den) > ")) if op == "*": sol = mult(n1, d1, n2, d2) showSol(sol) if op == "/": sol = div(n1, d1, n2, d2) showSol(sol) if op == "+": sol = add(n1, d1, n2, d2) showSol(sol) if op == "-": sol = sub(n1, d1, n2, d2) showSol(sol) if __name__ == '__main__': main()

What might be a good place to start or what might be some useful tools to use? Any advice is appreciated.

Also, if you have any ideas on how to refactor my code or make it more efficient those are welcome as well.

Thanks!