from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.uix.label…
- User
from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.uix.label import Label from kivy.uix.button import Button from kivy.uix.popup import Popup from kivy.graphics import Color from kivy.uix.screenmanager import ScreenManager, Screen
class HealthyBMIAppli(App): def build(self): sm = ScreenManager() sm.add_widget(LoginScreen(name='login')) sm.add_widget(MainScreen(name='main')) return sm
class LoginScreen(Screen): def init(self, **kwargs): super(LoginScreen, self).init(**kwargs) layout = BoxLayout(orientation='vertical') self.add_widget(layout)
codelabel = Label(text='Healthy BMI!', font_size=30, color=[0.5, 0.8, 0.2, 1], halign='center', valign='middle') layout.add_widget(label) button = Button(text='Login', font_size=20) layout.add_widget(button) self.button = button def on_button_press(self): sm = self.parent sm.current = 'main'class MainScreen(Screen): def init(self, **kwargs): super(MainScreen, self).init(**kwargs) layout = BoxLayout(orientation='vertical') self.add_widget(layout)
codelabel = Label(text='Enter your height and weight to calculate your BMI', font_size=20, color=[0.5, 0.8, 0.2, 1], halign='center', valign='middle') layout.add_widget(label) input_height = TextInput(multiline=False, hint_text='Height (in cm)') input_weight = TextInput(multiline=False, hint_text='Weight (in kg)') calculate_button = Button(text='Calculate BMI', font_size=20) layout.add_widget(input_height) layout.add_widget(input_weight) layout.add_widget(calculate_button) self.calculate_button = calculate_button def on_calculate_button_press(self): height = float(self.ids.input_height.text) weight = float(self.ids.input_weight.text) bmi = weight / (height ** 2) * 10000 popup = Popup(title='Your BMI', content=Label(text=f'Your BMI is {bmi:.2f}'), size_hint=(None, None), size=(200, 100)) popup.open() - Assistant