'How can I verify that my textfield is empty?
def check_full_name(self):
toast("You have to enter your full name to use the app correctly ! ")
MDTextFieldRound:
id:user_app
hint_text: "Full Name"
size_hint_x: None
size_hint_y: 0.08
width: 247
font_size: 18
pos_hint: {'center_x':0.5, 'center_y':0.62}
on_release: app.check_full_name() if user_app.text == '' else app.root.current = "accueil"
I don't know why it doesn't work, I want that when a field is empty calls my check_full_name function.Thanks for answering
Solution 1:[1]
According to your question, this should fix your problem:
.py file
from kivymd.app import MDApp
from kivymd.toast import toast
class PyApp(MDApp):
def on_start(self):
if self.root.ids.user_app.text == '':
self.check_full_name()
else:
self.root.ids.user_app.current = "accueil"
def check_full_name(self):
toast("You have to enter your full name to use the app correctly ! ")
PyApp().run()
.kv file
FloatLayout:
MDTextFieldRound:
id:user_app
hint_text: "Full Name"
size_hint_x: None
size_hint_y: 0.08
width: 247
font_size: 18
pos_hint: {'center_x':0.5, 'center_y':0.62}
on_text_validate: app.on_start()
Solution 2:[2]
class SplashScreenApp(MDApp):
dialog = None
def build(self):
dialog = None
self.title = "ReviewinApp"
global sm
sm = ScreenManager()
sm.add_widget(Builder.load_file("splash.kv"))
sm.add_widget(Builder.load_file("accueil.kv"))
sm.add_widget(Builder.load_file('conditions.kv'))
sm.add_widget(Builder.load_file("register.kv"))
sm.add_widget(Builder.load_file("faq.kv"))
sm.add_widget(Builder.load_file("login.kv"))
sm.add_widget(Builder.load_file("User2.kv"))
self.theme_cls.theme_style = "Light"
return sm
def on_start(self):
if self.root.ids.user_app.text == ' ':
toast("Please register correctly")
else:
toast("It's okay")
```
MDFillRoundFlatButton:
text: "Finish !"
font_size: "20sp"
font_name: "OpenSans"
pos_hint: {'center_x':0.5, 'center_y':0.07}
halign: 'center'
theme_text_color:'Custom'
text_color: 255/255, 255/255, 255/255, 1
size_hint: (0.58, 0.06)
md_bg_color: 62/255, 216/255, 133/255, 1
background_normal:''
on_press: app.on_start()
```
The python file and the kivy files are on different pages. One with extension .kv and one with .py
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ten Kho |
| Solution 2 | Magnetic Kyubi |
