Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to stop my entire python program from closing?

I am new to Python, so after making simple programs I am making a program. Using Tkinter I have managed to create the main screen and login screen(login form GUI). The functionality works however, if I do not want to log in and click on the back button, it should close the login screen(login form GUI), but it closes the entire program.

How do I avoid that?

Here is how I created the application.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

class LoginFrame(ttk.Frame):
    def __init__(self, container):
        super().__init__(container)
        self.__createMain__()

    # Creates the widgets for the Main Screen
    def __createMain__(self):

        #Some Labels and entry buttons code

        Button2 = Button(self, text='Close', command=self.Closes).place(x=200, y=140)


    # Closes the main program
    def Closes(self):
        quit()


class Login(tk.Tk):
    def __init__(self):
        super().__init__()
        self.title('Login Form')
        self.geometry('350x300')
        self.minsize(200,300)
        self.maxsize(500,500)
        self.__create_widgets()

    def __create_widgets(self):
        # create the input frame
        First_Frame = LoginFrame(self)
        First_Frame.place(height=200, width=700, x=20, y=20)

I am calling the Login class to my main program through a command, it opens up but I cannot close it. How can I do it?

>Solution :

Use this code.

This will close the full login screen.


class LoginFrame(ttk.Frame):
    def __init__(self, container):
        self.con = container
        super().__init__(container)
        self.__createMain__()

    # Creates the widgets for the Main Screen
    def __createMain__(self):

        #Some Labels and entry buttons code

        Button2 = Button(self, text='Close', command=self.Closes).place(x=200, y=140)


    # Closes the main program
    def Closes(self):
        self.con.destroy()


class Login(tk.Tk):
    def __init__(self):
        super().__init__()
        self.title('Login Form')
        self.geometry('350x300')
        self.minsize(200,300)
        self.maxsize(500,500)
        self.__create_widgets()

    def __create_widgets(self):
        # create the input frame
        First_Frame = LoginFrame(self)
        First_Frame.place(height=200, width=700, x=20, y=20)





But if you want to close the LoginFrame Only then change closes function to this.

# Closes the main program
def Closes(self):
    self.destroy()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading