How To Let Your Main Window Appear after succesful login in Tkinter(PYTHON 3.6

AD WAN

This is ui which comes with default user name and password but after successful login the main UI needs to appear

Challenge

  1. when you correctly input the user name and password the main window doesn't open but rather when you click cancel or close button then it opens

Finding solution

  1. Main window should appear after successfully login with the default password and user name
from tkinter import *
from tkinter import ttk
from tkinter import messagebox


def try_login():               # this my login function  
    if name_entry.get()==default_name and password_entry.get() == 
       default_password:
       messagebox.showinfo("LOGIN SUCCESSFULLY","WELCOME")
    else:
       messagebox.showwarning("login failed","Please try again" )


def cancel_login():        # exit function
    log.destroy()


default_name=("user")      #DEFAULT LOGIN ENTRY
default_password=("py36")


log=Tk()                   #this login ui
log.title("ADMIN-LOGIN")
log.geometry("400x400+400+200")
log.resizable (width=FALSE,height=FALSE)


LABEL_1 = Label(log,text="USER NAME")
LABEL_1.place(x=50,y=100)
LABEL_2 = Label(log,text="PASSWORD")
LABEL_2.place(x=50,y=150)

BUTTON_1=ttk. Button(text="login",command=try_login)
BUTTON_1.place(x=50,y=200)
BUTTON_1=ttk. Button(text="cancel",command=cancel_login)
BUTTON_1.place(x=200,y=200)

name_entry=Entry(log,width=30)
name_entry.place(x=150,y=100)
password_entry=ttk. Entry(log,width=30,show="*")
password_entry.place(x=150,y=150)

log. mainloop()



MAIN_WINDOW=Tk()      #after successful this main ui should appear

MAIN_WINDOW.geometry("600x500+300+100")

MENU_1 = Menu(MAIN_WINDOW)
MAIN_WINDOW.config(menu=MENU_1)

SETTINGS_1 = Menu(MENU_1,tearoff=0)
MENU_1.add_cascade(label="SETTINGS",menu=SETTINGS_1,underline=0)
SETTINGS_1.add_command(label="Change Password")

MAIN_WINDOW. mainloop()

I would appreciate if the answers comes in functions as am newbie in python and programming in general

Ethan Field

The below code can be used for the desired effect and is commented to show what is happening each step of the way:

from tkinter import * #Imports Tkinter
import sys #Imports sys, used to end the program later

root=Tk() #Declares root as the tkinter main window
top = Toplevel() #Creates the toplevel window

entry1 = Entry(top) #Username entry
entry2 = Entry(top) #Password entry
button1 = Button(top, text="Login", command=lambda:command1()) #Login button
button2 = Button(top, text="Cancel", command=lambda:command2()) #Cancel button
label1 = Label(root, text="This is your main window and you can input anything you want here")

def command1():
    if entry1.get() == "user" and entry2.get() == "password": #Checks whether username and password are correct
        root.deiconify() #Unhides the root window
        top.destroy() #Removes the toplevel window

def command2():
    top.destroy() #Removes the toplevel window
    root.destroy() #Removes the hidden root window
    sys.exit() #Ends the script


entry1.pack() #These pack the elements, this includes the items for the main window
entry2.pack()
button1.pack()
button2.pack()
label1.pack()

root.withdraw() #This hides the main window, it's still present it just can't be seen or interacted with
root.mainloop() #Starts the event loop for the main window

This makes use of the Toplevel widget in order to create a window which asks for the users details and then directs them to the main window which you can setup as you please.

You are also still able to use the pop up messages you have used in your example and if required you can also change the size of the Toplevel widget.

Please be advised however that this is not a particularly secure way of managing passwords and logins. As such I would suggest that you look up the proper etiquette for handling sensitive information in programming.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

After a succesful sign-in when user click on the back button of the browser, "login" page should not appear

From Dev

How to get Login succesful alert to trigger only one time after signing in

From Dev

Login should be succesful but does not link to my main menu interface

From Dev

How to show login window and hide main window

From Dev

How to show login window and hide main window

From Dev

teststack white get the main window after the login window

From Dev

How do I edit the list of Window Managers that appear in Gnome Login?

From Dev

How to set your main window invisble to show a image as main window in WPF

From Dev

how to let a login button become a drop down menu after click

From Dev

How to close a login dialog and show the main window (PyQt4)

From Dev

Custom widget does not appear on Main Window

From Dev

Maven/Jacoco - after succesful tests and jacoco datafiles merge, how to get a merged report?

From Dev

How to open emacs in new window after using ssh login

From Dev

How can I make a terminal with 3 tabs appear after startup?

From Dev

How to make a block to appear on the page after 3 seconds? CSS

From Dev

How can I make a terminal with 3 tabs appear after startup?

From Dev

After login a terminal windows appear (Xubuntu 14.04)

From Dev

terminal window appears after login?

From Dev

Remote login onto server and let someone else see your shell?

From Dev

Remote login onto server and let someone else see your shell?

From Dev

close javafx login window after successfull login

From Dev

close javafx login window after successfull login

From Dev

after click back button in main activity it going to back to login ,HOW TO STOP TO GO LOGIN AGAIN

From Dev

How to stop graying out of main window menu after activation of child window?

From Dev

How to not let sites block your iframe?

From Dev

i am trying to redirect a user after a succesful login to another page(homeDemo.php) but it doesnt seem to be redirecting. i am using php

From Dev

How to make a main div appear next to a sidebar

From Dev

How to make a main div appear next to a sidebar

From Dev

How to verify in protractor navigation to 3rd party page such login with your Google account?

Related Related

  1. 1

    After a succesful sign-in when user click on the back button of the browser, "login" page should not appear

  2. 2

    How to get Login succesful alert to trigger only one time after signing in

  3. 3

    Login should be succesful but does not link to my main menu interface

  4. 4

    How to show login window and hide main window

  5. 5

    How to show login window and hide main window

  6. 6

    teststack white get the main window after the login window

  7. 7

    How do I edit the list of Window Managers that appear in Gnome Login?

  8. 8

    How to set your main window invisble to show a image as main window in WPF

  9. 9

    how to let a login button become a drop down menu after click

  10. 10

    How to close a login dialog and show the main window (PyQt4)

  11. 11

    Custom widget does not appear on Main Window

  12. 12

    Maven/Jacoco - after succesful tests and jacoco datafiles merge, how to get a merged report?

  13. 13

    How to open emacs in new window after using ssh login

  14. 14

    How can I make a terminal with 3 tabs appear after startup?

  15. 15

    How to make a block to appear on the page after 3 seconds? CSS

  16. 16

    How can I make a terminal with 3 tabs appear after startup?

  17. 17

    After login a terminal windows appear (Xubuntu 14.04)

  18. 18

    terminal window appears after login?

  19. 19

    Remote login onto server and let someone else see your shell?

  20. 20

    Remote login onto server and let someone else see your shell?

  21. 21

    close javafx login window after successfull login

  22. 22

    close javafx login window after successfull login

  23. 23

    after click back button in main activity it going to back to login ,HOW TO STOP TO GO LOGIN AGAIN

  24. 24

    How to stop graying out of main window menu after activation of child window?

  25. 25

    How to not let sites block your iframe?

  26. 26

    i am trying to redirect a user after a succesful login to another page(homeDemo.php) but it doesnt seem to be redirecting. i am using php

  27. 27

    How to make a main div appear next to a sidebar

  28. 28

    How to make a main div appear next to a sidebar

  29. 29

    How to verify in protractor navigation to 3rd party page such login with your Google account?

HotTag

Archive