Sunday, October 17, 2021

Login App

 



login.py


from kivy.lang import Builder

from kivymd.app import MDApp



class MainApp(MDApp):

    def build(self):

        self.theme_cls.theme_style = "Dark"

        self.theme_cls.primary_palette = "BlueGray"

        return Builder.load_file('login.kv')

    def logger(self):

        if(self.root.ids.user.text != ""):

            self.root.ids.welcome_label.text = \

                f'Hello {self.root.ids.user.text}!'

    def clear(self):

        self.root.ids.welcome_label.text = 'WELCOME'

        self.root.ids.user.text = ''

        self.root.ids.password.text = ''


MainApp().run()


login.kv


Screen:

    MDCard:
        size_hint: None, None
        size: 300,400
        pos_hint: {"center_x": 0.5, "center_y": 0.5}
        elevation: 10
        padding: 25
        spacing: 25
        orientation: 'vertical'

        MDLabel:
            id: welcome_label
            text: "WELCOME"
            font_size: 40
            halign: 'center'
            size_hint_y: None
            height: self.texture_size[1]
            padding_y:15

        MDTextFieldRound:
            id:user
            hint_text: "username"
            icon_right: "account"
            size_hint_x: None
            width: 200
            font_size: 18
            pos_hint: {"center_x": 0.5}

        MDTextFieldRound:
            id:password
            hint_text: "password"
            icon_right: "eye-off"
            size_hint_x: None
            width: 200
            font_size: 18
            pos_hint: {"center_x": 0.5}
            password: True

        MDRoundFlatButton:
            text: "Log In"
            font_size: 12
            pos_hint: {"center_x": 0.5}
            on_press: app.logger()

        MDRoundFlatButton:
            text: "Clear"
            font_size: 12
            pos_hint: {"center_x": 0.5}
            on_press: app.clear()

        Widget:
            size_hint_y: None
            height: 10