Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Not redirecting to another page main.py after user fill in and click register button and store it on .ini local database on python using kivy

$
0
0

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, Screenfrom kivy.lang import Builderfrom kivymd.uix.textfield import MDTextFieldfrom kivymd.uix.button import MDFlatButtonfrom kivymd.uix.boxlayout import MDBoxLayoutfrom kivymd.app import MDAppfrom kivy.config import ConfigParserimport subprocess# Define the registration screenclass 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 screenkv = '''<RegistrationScreen>:        name: "registration_screen"'''# Load the KV string into the applicationBuilder.load_string(kv)# Define the MDApp subclassclass 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 RegistrationAppif __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 MDAppfrom kivy.uix.screenmanager import Screen, ScreenManagerfrom kivymd.uix.bottomnavigation import MDBottomNavigationfrom kivy.lang import BuilderKV = '''<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):    passclass Screen2(Screen):    passclass Screen3(Screen):    passclass Screen4(Screen):    passclass Screen5(Screen):    passsm = 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.


Viewing all articles
Browse latest Browse all 23131

Trending Articles