0

with an error which is impossible to fix under my hands. I find a defined variable after it has been opened I want the page to close so not all windows are open however when I load new user screen once they have done filled in new user details, I put a button in to which it will redirect them to existingUserEntry page ,which it is saying it cannot invoke the button, any help is necessary thanks?

def existingUserEntry():
    intitialScreen.destroy()
    login = False
    global existingUserScreen, usernameEntry, passwordEntry  
    existingUserScreen = Tk() # Set up a screen
    existingUserScreen.title("Existing User Login Screen")# Set a caption
    existingUserScreen.config(bg = "WHITE")# Set the background colour
    existingUserScreen.geometry("350x150")# Set the size of the window
    # Code for the username entry box.    
    usernameLabel = Label(existingUserScreen, text = "User name:")# Username Text box
    usernameLabel.config(bg = "PALE GREEN", font=('Helvetica', 12))# Formatting Features
    usernameLabel.pack()
    usernameEntry = ttk.Entry(existingUserScreen, font = "bold", width = 30)
    usernameEntry.pack()
    # Code for the password entry box.
    passwordLabel = Label(existingUserScreen, text = "Password:")# Password Text box
    passwordLabel.config(bg = "PALE GREEN", font=('Helvetica', 12))# Formatting Features
    passwordLabel.pack()
    passwordEntry = ttk.Entry(existingUserScreen, font = "bold", width = 30, show="*")
    passwordEntry.pack() 
    # Code for the sign in button.
    signInButton = Button(existingUserScreen, text="Sign in", width=10, command=verifyLoginDetails)
    signInButton.pack(expand = 1)# Placement of the Sign In button
    existingUserScreen.mainloop()

#Code for a button to allow new users to login to profile after creating one
    newUserSignInButton = Button(newUserScreen, text=" Back to Login Screen", width=15, command=backToLoginScreen)
    newUserSignInButton.config(height= 1, width= 40)
    newUserSignInButton.pack(expand= 4)
    newUserScreen.mainloop()
    newUserScreen = Button(intitialScreen, text="Existing User Sign In", width=25, command=existingUserEntry)
PaulLAD
  • 9
  • 1
  • 2

1 Answers1

1
def existingUserEntry():
    intitialScreen.destroy()
    ....
    newUserScreen = Button(intitialScreen,...)

You are destroying your intitialScreen at the beginning of your method then trying to add a button to that container at the end which causes the error. You need to choose existing one for your widgets.

Also, please note that,

  • Don't create multiple Tk() instances. If you want another window (e.g. pop-up) use Toplevel() instead of Tk(). (There is only one Tk() in this code but it feels like you have more in your actual code)

  • If you don't know what you are exactly doing, you most likely don't want to use mainloop() anywhere but at the end of your program.

Community
  • 1
  • 1
Lafexlos
  • 7,618
  • 5
  • 38
  • 53