prathamt commited on
Commit
a9fa731
·
verified ·
1 Parent(s): fc042f4

Create ui.py

Browse files
Files changed (1) hide show
  1. ui.py +189 -0
ui.py ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ttkbootstrap as tb
2
+
3
+ from ttkbootstrap.constants import *
4
+
5
+ from tkinter import *
6
+
7
+ from ttkbootstrap.scrolled import ScrolledFrame
8
+
9
+ from quad import Quadratic
10
+
11
+ from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
12
+
13
+ from ttkbootstrap.dialogs import Messagebox
14
+
15
+
16
+
17
+ # Most variables are named a,b,c according to ax² + bx + c in a quadratic equation
18
+
19
+
20
+
21
+ def plot():
22
+
23
+
24
+
25
+ # Collect all inputs
26
+
27
+ a_entryInput = a_entry.get()
28
+
29
+ b_entryInput = b_entry.get()
30
+
31
+ c_entryInput = c_entry.get()
32
+
33
+
34
+
35
+ try:
36
+
37
+ a = float(a_entryInput)
38
+
39
+ b = float(b_entryInput)
40
+
41
+ c = float(c_entryInput)
42
+
43
+ eqn = Quadratic(a,b,c)
44
+
45
+
46
+
47
+ #--------------------------------------------------------------------------
48
+
49
+ # Background Graph Frame
50
+
51
+ graph_frame = ScrolledFrame(root, width = 800, height = 500)
52
+
53
+ graph_frame.grid(row = 1, column = 0,pady = 10)
54
+
55
+
56
+
57
+ fig = eqn.drawFigure()
58
+
59
+
60
+
61
+ canvas = FigureCanvasTkAgg(figure = fig, master = graph_frame)
62
+
63
+ canvas.draw()
64
+
65
+ canvas.get_tk_widget().pack()
66
+
67
+
68
+
69
+ toolbar = NavigationToolbar2Tk(canvas, graph_frame)
70
+
71
+ toolbar.update()
72
+
73
+
74
+
75
+ canvas.get_tk_widget().pack()
76
+
77
+ solution_label.config(text = "Solution : x₁ = {0}, x₂ = {1}".format(eqn.solveQuad()[0], eqn.solveQuad()[1]))
78
+
79
+
80
+
81
+ except:
82
+
83
+ Messagebox.show_error(title = "Error", message = "User entered wrong value")
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+ # Base window widget
92
+
93
+ root = tb.Window(themename="vapor")
94
+
95
+ root.geometry("720x720")
96
+
97
+ root.title("Quadratic Equation Solver")
98
+
99
+
100
+
101
+ # Font data
102
+
103
+ font = ("Nunito", 12)
104
+
105
+
106
+
107
+ # Frame containing the entry for the three arguments
108
+
109
+ top_frame = tb.Frame(root)
110
+
111
+ top_frame.grid(row = 0, column = 0,padx = 10, pady = 20)
112
+
113
+
114
+
115
+ # Entry for the three arguments
116
+
117
+ a_frame = tb.Frame(top_frame)
118
+
119
+ a_frame.grid(row = 0, column = 0, padx=5)
120
+
121
+
122
+
123
+ a_label = tb.Label(a_frame, text= "a =", font = font)
124
+
125
+ a_label.grid(row = 0, column = 0)
126
+
127
+
128
+
129
+ a_entry = tb.Entry(a_frame, width = 30, font = font)
130
+
131
+ a_entry.grid(row = 0, column = 1)
132
+
133
+
134
+
135
+ b_frame = tb.Frame(top_frame)
136
+
137
+ b_frame.grid(row = 0, column = 1, padx=5)
138
+
139
+
140
+
141
+ b_label = tb.Label(b_frame, text = "b =", font = font)
142
+
143
+ b_label.grid(row = 0, column = 0)
144
+
145
+
146
+
147
+ b_entry = tb.Entry(b_frame, width = 30, font = font)
148
+
149
+ b_entry.grid(row = 0, column = 1)
150
+
151
+
152
+
153
+ c_frame = tb.Frame(top_frame)
154
+
155
+ c_frame.grid(row = 0, column = 2, padx=5)
156
+
157
+
158
+
159
+ c_label = tb.Label(c_frame, text = "c =", font = font)
160
+
161
+ c_label.grid(row = 0, column = 0)
162
+
163
+
164
+
165
+ c_entry = tb.Entry(c_frame, width = 30, font = font)
166
+
167
+ c_entry.grid(row = 0, column = 1)
168
+
169
+
170
+
171
+
172
+
173
+ # Button to plot the matplotlib graph
174
+
175
+ plot_button = tb.Button(top_frame, width = 70, text = "Plot", command = plot)
176
+
177
+ plot_button.grid(row = 1, column = 1, pady = 15)
178
+
179
+
180
+
181
+ # Label containing the solution to the equation
182
+
183
+ solution_label = tb.Label(root,font = (font[0], 15), text = "")
184
+
185
+ solution_label.grid(row = 2, column = 0, pady = 10)
186
+
187
+
188
+
189
+ root.mainloop()