PROFIT AND LOSS CALCULATOR PYTHON KIVY

Please if you like my content Please do not forget to support this
 channel on PayPal now for $1 only! 
Or less 


from kivy.app import App
from kivy.properties import StringProperty
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import Screen, ScreenManager

screenmanager = """

ScreenManager:
MainScreen:


<MainScreen>:
name: 'main'
RelativeLayout:
orientation: 'vertical'
pos: self.pos

Label:
text: 'Welcome to profit and loss calculator!'
pos_hint: {'center_x': 0.5, 'center_y':0.905}
font_size: (self.height/15)* 0.75


Label:
text:'Enter Total Profit!'
pos_hint:{'center_x':0.3, 'center_y': 0.705}
font_size: (self.height/15)* 0.65


TextInput
id: profit
size_hint: 0.3, 0.05
pos_hint:{'center_x':0.6, 'center_y': 0.705}
text:root.profit

Label:
text:'Enter Total Loss!'
pos_hint:{'center_x':0.3, 'center_y': 0.605}
font_size: (self.height/15)* 0.65


TextInput
id: loss
size_hint: 0.3, 0.05
pos_hint:{'center_x':0.6, 'center_y': 0.605}
text: root.loss


Button:
text: 'calculate'
size_hint: .3, .1
pos_hint:{'center_x':0.47, 'center_y': 0.505}
on_press: root.calculate()

TextInput:
text: '0'
id: answer
pos_hint:{'center_x':0.47, 'center_y': 0.305}
size_hint: 0.3, 0.15








"""


class Pal(App):

def build(self):
screen = Builder.load_string(screenmanager)
return screen


class MainScreen(Screen):
profit = StringProperty('0')
loss = StringProperty('0')

def calculate(self):
try:
profitvariable = self.ids.profit.text
lossvariable = self.ids.loss.text
answer = 0
answer = int(profitvariable) - int(lossvariable)
print(answer)

if answer > 0:
answer = self.ids.answer.text = str(answer) + str(' Profit')

elif answer == 0:
answer = self.ids.answer.text = str(answer)

else:
answer = self.ids.answer.text = str(answer) + str(' Loss')
except ValueError:
answer = self.ids.answer.text = str('Invalid Value!')


sm = ScreenManager()
sm.add_widget(MainScreen(name='main'))

Pal().run()

No comments:

Post a Comment

Drawing App For Kivy

  Below here is the source code for Drawing Application for kivy. Please if you like this content.  Don't forget to Subscribe to my YouT...