11
22from kivymd .app import MDApp
33from kivymd .uix .screen import Screen
4- from kivymd .uix .button import MDButton
5- from kivymd .uix .textfield import MDTextField
4+ from kivymd .uix .boxlayout import MDBoxLayout
5+ from kivymd .uix .label import MDLabel
6+ from helpers import username_helper , password_helper
67from kivy .lang import Builder
7- from kivymd .uix .button import MDButton
8- from kivymd .uix .button import MDButtonIcon
8+ from kivymd .uix .button import MDRaisedButton
9+ from kivymd .uix .dialog import MDDialog
910
10- username_input = """
11- MDTextField:
12- hint_text: "Enter username"
13- helper_text: "or click on forgot username"
14- pos_hint:{'center_x': 0.5, 'center_y': 0.5}
15- size_hint_x:None
16- width:300
17- """
18-
19- class TodoApp (MDApp ):
11+ class Demo (MDApp ):
2012
2113 def build (self ):
2214 screen = Screen ()
15+ self .theme_cls .primary_pelatte = "Green"
2316
24- # user_name = MDTextField(text="Enter username", pos_hint={"center_x":0.5, "center_y":0.5},
25- # size_hint_x=None, width=400)
17+ 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 )
22+ )
2623
27- username = Builder .load_string (username_input )
28- button = MDButtonIcon (text = "Click Me" , pos_hint = {"center_x" :0.5 , "center_y" :0.5 })
2924
25+ # Widgets
26+ label = MDLabel (text = "Login" , halign = "center" )
27+ self .username = Builder .load_string (username_helper )
28+ 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 )
3031
31-
32- # screen.add_widget(username)
33- screen .add_widget (button )
32+ # Add widgets in the box layout
33+ box_layout .add_widget (label )
34+ box_layout .add_widget (self .username )
35+ box_layout .add_widget (self .password )
36+ box_layout .add_widget (button )
3437
35-
36- return screen
38+ box_layout . height = self . username . height + self . password . height + 40
39+ box_layout . width = 400
3740
38- TodoApp ().run ()
41+ # Add the box layout in the screen
42+ screen .add_widget (box_layout )
43+
44+ return screen
45+
46+ # Function for showing the dialog
47+ 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+
56+ if __name__ == "__main__" :
57+ Demo ().run ()
0 commit comments