Multiple Windows in Tkinter

Hello! Please help to resolve the issue in my Tkinter code…

Problem Statement:
I have a simple tkinter logIn page that contains a login button. On clicking this button, I want to close this login page and wants to open (or run) a new python file that displays main project GUI (that contains many tkinter widgets buttons, text boxes, labels etc.). Further, on this main GUI, I have a “Back to Login Window” Button. When i click this button then I want to close this main GUI page and wants to display again Login page. Upto this stage, my code do as i want (code is working as i desires).

BUT,after this when I again, Press login button to close it and open main GUI but not successfull…my main GUI page closes but this does not open main GUI page again…why it so? please help me.

(1) I have made a small project with two python files, with names MultiWindowsLogIn.py and the other is mainGUI.py.

(2) Code of MultiWindowsLogIn.py is as:

`from tkinter import *

def login():
logInWindow.quit()
logInWindow.destroy()
import mainGUI

logInWindow = Tk()
logInWindow.title(“Login Window Title”)
logInWindow.geometry(‘600x400’)

logInButton = Button(logInWindow, text=“Login”, width=15, font=(‘times new roman’, 15, ‘bold’), bd=2, command=login)
logInButton.place(x=200,y=250)

logInWindow.mainloop()`

image

(3) Code of mainGUI.py is as:
`from tkinter import *

def backToLoginPage():
guiWindow.quit()
guiWindow.destroy()
import MultiWindowsLogIn

guiWindow = Tk()
guiWindow.title(“Student Registration System”)
guiWindow.geometry(‘500x200+0+0’)

backButton = Button(guiWindow, text=“Back to Login Window”, font=(‘times new roman’, 15, ‘bold’), bd=3, command=backToLoginPage)
backButton.place(x=150, y=100)

guiWindow.mainloop()`

Please help me to solve the issue, If there is some other way to achieve the desired output then please let me know…Thanks

Hello,
sorry, this is a little confusing. Can you please rephrase? Thanks.

Also did you run tests, do you have any error messages that you can share? It’s hard to debug code that uses libraries by looking at it, who knows what happens under the hood.