Skip to content

Instantly share code, notes, and snippets.

@c34s3r
Created November 14, 2015 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c34s3r/dbcef3046babc9fca06d to your computer and use it in GitHub Desktop.
Save c34s3r/dbcef3046babc9fca06d to your computer and use it in GitHub Desktop.
quadratic equations with kivy and python...
I wrote a quadratic equations GUI based script..
I used kivy and python, the formula is also the Almighty formula..
I used the floatlayout so that it maintains it's look even on landscape...
here's the code below...
for the. py file.....
#-*-coding:utf8;-*-
#qpy:2
#qpy:kivy
from math import sqrt
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.lang import Builder
class for_quadratic(FloatLayout):
def solve_solution(self):
self.result_box= self.ids.result_label
self.value_a=self.ids.value_one.text
self.value_b=self.ids.value_two.text
self.value_c=self.ids.value_three.text
if (self.value_a==""):
self.value_a="1"
if (self.value_b==""):
self.value_b="1"
if (self.value_c==""):
self.value_c="1"
self.a=int(self.value_a)**2
self.b=int(self.value_b)
self.c=int(self.value_c)
self.g=self.b**2
self.h=4*self.a*self.c
self.I=abs(self.g-self.h)
self.k=self.I
self.formula= sqrt(self.k)
self.root_one=(-self.b-self.formula)/2*self.a
self.root_two=(-self.b+self.formula)/2*self.a
self.result_box.text=("the roots are \n {} and {}"
.format(round(self.root_one),round(self.root_two)))
class QuadraticApp(App):
def build(self):
return for_quadratic()
QuadraticApp().run()
and for the kv file....
###kivy for quadratuc
<for_quadratic>:
FloatLayout:
Label:
id: main_label
text:"QUADRATIC EQUATIONS"
size_hint: None,None
width: root.width/2
height: 45
font_size: 30
bold: True
pos_hint: {"x":.25,"top":1}
Label:
id: label_one
text: "VALUE A"
size_hint: None,None
width:root.width/2
font_size: 20
height: 40
bold: True
pos_hint:{"x":0,"y":.8}
TextInput:
id: value_one
hint_text: "type"
size_hint: None,None
width: root.width/2
height: 55
font_size: 20
bold: True
multiline: False
padding: root.height/self.height
pos_hint: {"x":.5,"y":.8}
Label:
id: label_two
text: "VALUE B"
size_hint: None,None
width:root.width/2
font_size: 20
height: 40
bold: True
pos_hint: {"x":0,"y":.7}
TextInput:
id: value_two
hint_text: "type"
size_hint: None,None
width: root.width/2
height: 55
font_size: 20
bold: True
multiline: False
padding: root.height/self.height
pos_hint: {"x":.5,"y":.7}
Label:
id: label_three
text: "VALUE C"
size_hint: None,None
width:root.width/2
font_size: 20
height: 40
bold: True
pos_hint: {"x":0,"y":.6}
TextInput:
id: value_three
hint_text: "type"
size_hint: None,None
width: root.width/2
height: 55
font_size: 20
bold: True
multiline: False
padding: root.height/self.height
pos_hint: {"x":.5,"y":.6}
Button:
id: submit_button
text: "CALCULATE"
size_hint: None,None
width: root.width/2
font_size: 25
height: 57
italic: True
pos_hint: {"x":.5,"y":.5}
on_press: root.solve_solution()
Label:
id: result_label
text:"...."
size_hint: None,None
width: root.width
height: 100
font_size: 25
bold: True
pos_hint: {"x":0,"y":.3}
Label:
text: " by vitriol"
size_hint: None,None
width: root.width/2
font_size: 20
color: 0,1,0,1
pos_hint: {"x":.25,"y":0}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment