Jump to content
from tkinter import *

root = Tk()
root.title("My Login")
root.geometry("650x650")

frame = Frame(root)

app = Frame(root)
app.grid

l = Label(root, text = "Login",font="Times 30", padx=5,  pady=5)
l.grid()

l1 = Label(root, text = "Username:",font="Times 30", padx=5,  pady=5)
l1.grid()

l2 = Label(root, text = "Password:",font="Times 30", padx=5,  pady=5)
l2.grid()

user = Entry(root)
user.grid( row= 1, column= 2)
user.configure(font = ("Courier", 44))
pass1 = Entry(root)
pass1.grid( row= 2, column= 2)
pass1.configure(font = ("Courier", 44))

username = "admin"
user = user.get()
password = "password"
pass1 = pass1.get()

def enter():
  if (user == username and pass1 == password):
   open() #Opens a directory
  else: 
    l3 = Label(root, text = "check login", font=("Courier", 22))
    l3.grid()
    
b1 = Button(app, text = "Enter", command = enter, font=("Courier", 44))
b1.grid()


root.mainloop()

The button doesn't seem to want to appear.

Link to comment
https://linustechtips.com/topic/1282454-tkinter-python-login/
Share on other sites

Link to post
Share on other sites

Ok new problem the code is skipping over the if and is automatically using the else. How do I fix my login?

from tkinter import *

root = Tk()
root.title("My Login")
root.geometry("650x650")

frame = Frame(root)

app = Frame(root)
app.grid

l = Label(root, text = "Login",font="Times 30", padx=5,  pady=5)
l.grid()

l1 = Label(root, text = "Username:",font="Times 30", padx=5,  pady=5)
l1.grid()

l2 = Label(root, text = "Password:",font="Times 30", padx=5,  pady=5)
l2.grid()

user = Entry(root)
user.grid( row= 1, column= 2)
user.configure(font = ("Courier", 44))
pass1 = Entry(root)
pass1.grid( row= 2, column= 2)
pass1.configure(font = ("Courier", 44))

user = user.get()
pass1 = pass1.get()

Username = "admin"
Password = "password"

def enter():
    if (user == Username and pass1 == Password):
        import subprocess
        subprocess.Popen("") #Directory would go here
    else: 
        l3 = Label(root, text = "check login", font=("Courier", 22))
        l3.grid()
    
b1 = Button(root, text = "Enter", command = enter, font=("Courier", 44))
b1.grid()


root.mainloop()

 

Link to comment
https://linustechtips.com/topic/1282454-tkinter-python-login/#findComment-14312313
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×