-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (54 loc) · 1.82 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import kivy
from kivymd.app import MDApp
from kivymd.uix.snackbar import Snackbar
from kivy.uix.widget import Widget
from kivy.lang import Builder
kivy.require('2.0.0')
# CFC is a python program with kivy as the frontend GUI which
# converts celsius to fahrenheit or fahrenheit to celsius.
__version__ = "1.5"
__author__ = "Naveed Nilawfar"
Builder.load_file('main.kv')
class CFCLayout(Widget):
"""The root Widget of CFC"""
def c2f_cal(self):
"""Converts celsius into farenheit"""
self.ids.afarenheit.text = ""
if self.ids.scelsius.text == "":
c2f_error = Snackbar(
text="You haven't entered any value to convert into farenheit"
)
c2f_error.open()
else:
answer = ""
self.ids.afarenheit.text = ""
c = self.ids.scelsius.text
answer = (float(c)*1.8)+32
self.ids.afarenheit.text = f'{answer}'
def f2c_cal(self):
"""Converts farenheit into celsius"""
self.ids.acelsius.text = ""
if self.ids.sfarenheit.text == "":
f2c_error = Snackbar(
text="You haven't entered any value to convert into celsius"
)
f2c_error.open()
else:
answer = ""
self.ids.acelsius.text = ""
f = self.ids.sfarenheit.text
answer = (float(f)-32)*5/9
self.ids.acelsius.text = f'{answer}'
class CFCApp(MDApp):
"""The app instance of CFC"""
def build(self):
"""Build the app"""
self.title = 'CFConverter'
self.icon = 'images/icon9.png'
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Green"
return CFCLayout()
if __name__ == '__main__':
CFCApp().run()