I want to get data from the TextField in the password manager screen and print it on the terminal, but I am unable to do it. Pls help.
P.S.: I have highlighted the required TextFields and Submit button.
<main.kv>
<DrawerClickableItem@MDNavigationDrawerItem>
focus_color: "#e7e4c0"
unfocus_color: "#fffcf4"
MDScreen:
MDNavigationLayout:
ScreenManager:
MDScreen:
MDBoxLayout:
orientation: "vertical"
MDBoxLayout:
adaptive_height: True
md_bg_color: "#fffcf4"
padding: "12dp"
MDLabel:
text: "CyberShield"
adaptive_height: True
pos_hint: {"center_y": .5}
MDBoxLayout:
MDNavigationRail:
id: navigation_rail
md_bg_color: "#fffcf4"
selected_color_background: "#e7e4c0"
ripple_color_item: "#e7e4c0"
MDNavigationRailMenuButton:
on_release: nav_drawer.set_state("open")
MDNavigationRailItem:
text: "Home"
icon: "home"
on_release:
screen_manager.current = "main_window"
MDNavigationRailItem:
text: "Passwords"
icon: "key"
on_release:
screen_manager.current = "passwordmanager"
ScreenManager:
id: screen_manager
main_window: main_window
settings: settings
passwordmanager: passwordmanager
Screen:
id: main_window
name: "main_window"
MDLabel:
text:"Hello"
halign:"center"
Screen:
id: passwordmanager
name: "passwordmanager"
website: website
load: load
username: username
passwords: passwords
submit: submit
MDGridLayout:
rows:3
cols:2
MDTextField:
id: website
multiline:False
hint_text:"Enter Website"
size_hint_x:0.5
icon_left:"web"
MDIconButton:
id: load
icon: "plus-box-multiple-outline"
MDTextField:
id: username
multiline:False
hint_text: "Enter Username"
size_hint_x:0.5
icon_left: "account-circle-outline"
MDIconButton:
id:pencil
icon:"pencil"
theme_text_color:"Hint"
MDTextField:
id: passwords
multiline:False
hint_text: "Enter Password"
size_hint_x: 0.5
password: True
icon_left: "key-variant"
MDIconButton:
id: showpassword
icon: "eye-off"
text:"Show Password"
pos_hint: {"center_y": 0.5}
theme_text_color: "Hint"
on_release:
self.icon = "eye" if self.icon == "eye-off" else "eye-off"
passwords.password = False if passwords.password is True \
else True
MDFillRoundFlatButton:
id: submit
text:"Submit"
pos_hint: {"center_x":.5, "center_y":.5}
on_release:
app.login_data()
MDNavigationDrawer:
id: nav_drawer
radius: 0, 16, 16, 0
md_bg_color: "#fffcf4"
elevation: 2
width: "240dp"
MDNavigationDrawerMenu:
MDBoxLayout:
orientation: "vertical"
adaptive_height: True
spacing: "12dp"
padding: 0, 0, 0, "12dp"
MDIconButton:
icon: "arrow-left"
on_release: nav_drawer.set_state("close")
MDBoxLayout:
adaptive_height: True
padding: "12dp", 0, 0, 0
DrawerClickableItem:
text: "Home"
icon: "home"
on_release:
screen_manager.current = "main_window"
DrawerClickableItem:
text: "Passwords"
icon: "key"
on_release:
screen_manager.current = "passwordmanager"
<main.py>
from
kivymd.app import MDApp
from kivy.lang import Builder
from kivy.properties import ObjectProperty
class CyberShieldApp(MDApp):
screen_manager = ObjectProperty(None)
def build(self):
self.screen = Builder.load_file("main.kv")
return self.screen
def login_data(self):
website = self.screen.screen_manager.passwordmanager.website.text
username = self.screen.screen_manager.passwordmanager.username.text
password = self.screen.screen_manager.passwordmanager.password.text
print(website)
print(username)
print(password)
if __name__ == "__main__":
app = CyberShieldApp()
app.run()