TAKING INPUT FROM USER USING MDTEXTFIELD WIDGET
Link Of Video On You Tube - https://youtu.be/Sgtui8zhMBI
Following are the steps that are required to take input from user :
1. Creating the App by importing the MDApp class of kivymd module.
2. Creating the Screen by using MDScreen class of kivymd module.
3. Creating Text Field using MDTextField Class
First Create a Python file (extension .py) then, create a kivy file (.kv extension) name of kivy file should be same as app name.
App name is the name of the class that consist of build function and created by inheriting the MDApp class
Following is the list of attributes used in this program :-
Attributes of MDScreen class
1. md_bg_color - To change the background color
2. radius - to change the corner radius of screen
Attributes of MDTextField class
1. hint_text - To print hint text on text field (Takes String).
2. helper_text - To print helper text on text field (Takes String).
3. heper_text_mode - To change the mode of helper_text (Takes on_focus and persistent).
4. pos_hint - To change the position of button (Takes values in dictionary format like pos_hint : {"center_x":.5,"center_y":.5}.
5. icon_right - name of icon to be printed on right side of text field.
Note :- you can get the list of ICON name by using this url
6. size_hint_x - to change the size of field along x axis (Takes float type values and None).
7. width - used when the value of size_hint_x is None (takes Numeric values).
8. color_mode - To change the color of text field (Takes values accent, primary)
9. line_color_focus - To change the color of text field line when it is focused (takes values in rgb format)
10. line_color_normal - To change the color of text field line when it is normal (takes values in rgb format).
11. icon_right_color - To change the color of right icon (takes values in rgb format).
12. multiline - To take multiline input from user (Takes True, False)
13. mode - To Change the mode of the text field ( Values can be rectangle, fill).
14. fill_color - used when mode is fill and change the background color of button (Takes values in rgb format)
Following is the code of this program :-
1. Code of Python program (Save it by .py extension)
from kivymd.app import MDApp
class Myapp(MDApp):
def build(self):
return
def get_data(self):
print("The data of text field is :: ",self.root.ids.data.text)
Myapp().run()
2. Code of Kivy program (Save it by name Myapp.kv)
MDScreen :
MDTextField :
id : data
hint_text : "Username"
icon_right : "account"
helper_text : "example@gmail.com"
helper_text_mode : "on_focus"
pos_hint : {"center_x":.5,"center_y":.5}
size_hint_x : None
width : 400
font_size : 25
line_color_normal : [1,0,0,1]
line_color_focus : [0,1,0,1]
icon_right_color : [0,0,1,1]
mode : "fill"
fill_color : [0,0,0,.6]
MDRectangleFlatIconButton :
text : 'Submit '
icon : "language-python"
pos_hint : {"center_x":.5,"center_y":.3}
font_size : 20
on_press : app.get_data()
Comments
Post a Comment