1-
1+ import subprocess
22from kivymd .app import MDApp
33from kivymd .uix .screen import Screen
44from kivymd .uix .boxlayout import MDBoxLayout
55from kivymd .uix .label import MDLabel
6- from helpers import username_helper , password_helper
76from kivy .lang import Builder
87from kivymd .uix .button import MDRaisedButton
98from kivymd .uix .dialog import MDDialog
109
10+ username_helper = """
11+ MDTextField:
12+ hint_text: "Enter your username"
13+ size_hint_x: None
14+ width: 400
15+ icon_right: "account"
16+ """
17+
18+ password_helper = """
19+ MDTextField:
20+ hint_text: "Enter your password"
21+ helper_text: "or click on forgot password"
22+ helper_text_mode: "on_focus"
23+ size_hint_x: None
24+ width: 400
25+ icon_right: "key-variant"
26+ password: True
27+ """
28+
29+
30+
1131class Demo (MDApp ):
1232
1333 def build (self ):
1434 screen = Screen ()
15- self .theme_cls .primary_pelatte = "Green"
35+ self .theme_cls .primary_palette = "Green"
1636
1737 box_layout = MDBoxLayout (
18- orientation = "vertical" ,
19- spacing = 20 ,
20- pos_hint = {"center_x" :0.5 , "center_y" :0.5 },
21- size_hint = (None , None )
38+ orientation = "vertical" ,
39+ spacing = 20 ,
40+ pos_hint = {"center_x" : 0.5 , "center_y" : 0.5 },
41+ size_hint = (None , None )
2242 )
2343
24-
2544 # Widgets
2645 label = MDLabel (text = "Login" , halign = "center" )
2746 self .username = Builder .load_string (username_helper )
2847 self .password = Builder .load_string (password_helper )
29- button = MDRaisedButton (text = "Login" , pos_hint = {"center_x" :0.5 , "center_y" :0.5 },
30- on_release = self .show_values )
48+ button = MDRaisedButton (
49+ text = "Login" , pos_hint = {"center_x" : 0.5 , "center_y" : 0.5 },
50+ on_release = self .show_values
51+ )
3152
3253 # Add widgets in the box layout
3354 box_layout .add_widget (label )
@@ -42,16 +63,30 @@ def build(self):
4263 screen .add_widget (box_layout )
4364
4465 return screen
45-
66+
4667 # Function for showing the dialog
4768 def show_values (self , obj ):
48- close_btn = MDRaisedButton (text = "Close" )
49- more_btn = MDRaisedButton (text = "More" )
50- dialog = MDDialog (title = "Show details" ,
51- text = f"Username: { self .username .text } \n \n Password: { self .password .text } " ,
52- size_hint = (0.7 , 1 ),
53- buttons = [close_btn , more_btn ])
54- dialog .open ()
55-
69+ if self .username .text == "" :
70+ check_string = "Please enter username"
71+ else :
72+ check_string = "Username does not exist"
73+
74+ close_btn = MDRaisedButton (text = "Close" , on_release = self .close_dialog )
75+ more_btn = MDRaisedButton (text = "More" , on_release = self .open_home )
76+
77+ self .dialog = MDDialog (
78+ title = "Show details" ,
79+ text = f"Username: { check_string } \n \n Password: { self .password .text } " ,
80+ buttons = [close_btn , more_btn ]
81+ )
82+ self .dialog .open ()
83+
84+ def open_home (self , obj ):
85+ # Use subprocess to run home.py
86+ subprocess .run (["python" , "home.py" ])
87+
88+ def close_dialog (self , obj ):
89+ self .dialog .dismiss ()
90+
5691if __name__ == "__main__" :
5792 Demo ().run ()
0 commit comments