0

This is the code I have written. I have attempted to get a GUI that just places the Quadratic and Linear equation into the GUI so it can be solved in a visual way by the user

from tkinter import *
master = Tk()
var1 = IntVar() 
Checkbutton(master, text='male', variable=var1).grid(row=0, sticky=W) 
var2 = IntVar() 
Checkbutton(master, text='female', variable=var2).grid(row=1, sticky=W)
w = Canvas(master, width=40, height=60)
canvas_height=20
canvas_width=200
y = int(canvas_height / 2) 
w.create_line(0, y, canvas_width, y ) 
mainloop() 



from math import sqrt

print("Quadratic function : (a * x^2) + b*x + c")
a = float(input("a: "))
b = float(input("b: "))
c = float(input("c: "))

r = b**2 - 4*a*c
if a == 0:
    x = -c/b
    print("Linear Function: %f"%(x))


elif r > 0:
    num_roots = 2
    x1 = (((-b) + sqrt(r))/(2*a))     
    x2 = (((-b) - sqrt(r))/(2*a))
    print("There are 2 roots: %f and %f" % (x1, x2))
elif r == 0:
    num_roots = 1
    x = (-b) / 2*a
    print("There is one root: ", x)
else:
    num_roots = 0
    print("No roots, discriminant < 0.")
  • 2
    Hi, please state your problem – drops Aug 25 '20 at 07:24
  • Hey, Sorry thought I was clear in what I said. My problem is that I can't figure out how to have the code for the quadratic and linear equations be shown in a UI instead of just the terminal box in VS Code – Jordan Powter Aug 25 '20 at 07:32
  • Hello. Sorry it is still not clear: Do you want to print text in the UI or draw the function? In either case you should start by a tkinter tutorial or any UI related tutorial: UI applications are event based: user event trigger the next application response. In the above code nothing past the call to `mainloop` will be executed: `mainloop` is an infinite loop waiting for user graphical events to be dispatched to your UI widgets. – Jean-Marc Volle Aug 25 '20 at 08:18
  • You can use `Label` to show text and the quadratic equation, use `Entry` widget for inputs. Then use a button to trigger a function to solve the equation and update the result `Label`. – acw1668 Aug 25 '20 at 09:22

0 Answers0