So am not that good with python because am coming from php, and I want to develop this app, and want to use local storage to store user registration data after they register they will be redirected to the main.py page, so here is the registration_screen.py page code for registration and its code with useful #comment for easy understanding, please help me please.
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
from kivymd.uix.textfield import MDTextField
from kivymd.uix.button import MDFlatButton
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.app import MDApp
from kivy.config import ConfigParser
import subprocess
# Define the registration screen
class RegistrationScreen(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
# Create a vertical box layout for the registration screen
layout = MDBoxLayout(orientation='vertical', padding=40, spacing=20)
# Create text fields for username, email, and phone number
self.username_field = MDTextField(hint_text="Username")
self.email_field = MDTextField(hint_text="Email")
self.phone_field = MDTextField(hint_text="Phone Number")
# Create a button for registration
register_button = MDFlatButton(text="Register", on_release=self.register)
# Add widgets to the layout
layout.add_widget(self.username_field)
layout.add_widget(self.email_field)
layout.add_widget(self.phone_field)
layout.add_widget(register_button)
# Add the layout to the screen
self.add_widget(layout)
# Method to handle registration process
def register(self, *args):
# Retrieve user input from text fields
username = self.username_field.text
email = self.email_field.text
phone = self.phone_field.text
# Store user registration data locally
config = ConfigParser()
config.read('registration.ini')
if 'Registration' not in config.sections():
config.add_section('Registration')
# Set user data
config.set('Registration', 'username', username)
config.set('Registration', 'email', email)
config.set('Registration', 'phone', phone)
# Write data to file
with open('registration.ini', 'w') as config_file:
config.write(config_file)
# Open main.py using subprocess.Popen when registration is successful
subprocess.Popen(["python", "main.py"])
# Load the KV string defining the screen
kv = '''
<RegistrationScreen>:
name: "registration_screen"
'''
# Load the KV string into the application
Builder.load_string(kv)
# Define the MDApp subclass
class RegistrationApp(MDApp):
def build(self):
# Create a screen manager to manage different screens
self.manager = ScreenManager()
# Add the RegistrationScreen as the first screen
self.manager.add_widget(RegistrationScreen())
# Return the screen manager
return self.manager
# Run the RegistrationApp
if __name__ == "__main__":
RegistrationApp().run()
now here is the registration.ini file which contains
[Registration] username = email = phone =
and here is the main.py page code they are suppose to redirect to after registration, but instead when they click the register button from registration_screen.py they are not redirected to main.py and the code in registration.ini file gets deleted, please help me make this app a possibility because i am really getting frustrated and down, heres the main.py code where they are suppose to be redirected to.
from kivymd.app import MDApp
from kivy.uix.screenmanager import Screen, ScreenManager
from kivymd.uix.bottomnavigation import MDBottomNavigation
from kivy.lang import Builder
KV = '''
<MDBottomNavigation>:
MDBottomNavigationItem:
name: 'screen1'
text: 'Android'
icon: 'android'
MDLabel:
text: 'Android'
halign: 'center'
MDBottomNavigationItem:
name: 'screen2'
text: 'Apple'
icon: 'apple'
MDLabel:
text: 'Apple'
halign: 'center'
MDBottomNavigationItem:
name: 'screen3'
text: 'Linux'
icon: 'linux'
MDLabel:
text: 'Linux'
halign: 'center'
MDBottomNavigationItem:
name: 'screen4'
text: 'Windows'
icon: 'microsoft-windows'
MDLabel:
text: 'Windows'
halign: 'center'
MDBottomNavigationItem:
name: 'screen5'
text: 'YourItem'
icon: 'linux'
MDLabel:
text: 'YourItem'
halign: 'center'
'''
class Screen1(Screen):
pass
class Screen2(Screen):
pass
class Screen3(Screen):
pass
class Screen4(Screen):
pass
class Screen5(Screen):
pass
sm = ScreenManager()
sm.add_widget(Screen1(name='screen1'))
sm.add_widget(Screen2(name='screen2'))
sm.add_widget(Screen3(name='screen3'))
sm.add_widget(Screen4(name='screen4'))
sm.add_widget(Screen5(name='screen5'))
class TutorialsPointApp(MDApp):
def build(self):
Builder.load_string(KV)
return MDBottomNavigation()
if __name__ == '__main__':
TutorialsPointApp().run()
When clicked it delete the entire code in registration.ini and dosent redirect to main.py page after clicking the register button, please help me make this project a possibility.
I suspect you are getting an uncaught
Exceptionfrom your code:The
write()method takes no arguments as it writes to the last read file. Try changing that line to:In fact, you don't need the code: