AGE CALCULATOR KIVY

 This is the source code for making an Age Calculator With 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, NumericProperty
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import Screen, ScreenManager
from datetime import date

screenmanager = """

ScreenManager:
MainScreen:


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

Label:
text: 'Welcome to Age Calculator Kivy!'
pos_hint: {'center_x': 0.5, 'center_y':0.905}
font_size: (self.height/15)* 0.75


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


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

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


TextInput
id: currentyear
size_hint: 0.3, 0.05
pos_hint:{'center_x':0.62, '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()





Label:
text:'You are'
pos_hint:{'center_x':0.47, 'center_y': 0.355}
font_size: (self.height/15)* 0.65

Label:
id: age
text:str(root.finalage)
pos_hint:{'center_x':0.47, 'center_y': 0.255}
font_size: (self.height/15)* 0.65

Label:
text:'Years old!'
pos_hint:{'center_x':0.47, 'center_y': 0.155}
font_size: (self.height/15)* 0.65


"""


class Age(App):

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


class MainScreen(Screen):
number = 0
finalage = StringProperty(number)
currentyear = date.today().year
profit = StringProperty('0')
loss = StringProperty(str(currentyear))

def calculate(self):
try:
birth = self.ids.birthyear.text
currentyear = self.ids.currentyear.text
finalage = int(currentyear) - int(birth)
self.ids.age.text = str(finalage)
if finalage < 0:
self.ids.age.text = str('Invalid')

except ValueError:
pass


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

Age().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...