Ok so I'm trying to make a inter face with a password. my plan is to have a window open up with an input box where you type the password and then when you have the right password it brings you to the second screen with the stuff on it. right now my log in screen doesnt have a working password I've tryed everything as well. only thing working on it is the shutdown button at the bottom. The password is _____ and then you hit enter/return key to enter or atlest thats what i want i dont want a button.

here is my code any help would be greatful for i'm working on a importing school project and dont have a clue how to get it working. I maked the area with a hash tag #

from tkinter import *
import tkinter as tk

# Create the window

##t = Tk()
root = Tk()
root.title("NEOSA Corp Interface")

# Background
p = PhotoImage(file="CIA.gif")
l = Label(root, image=p)

# Password for main screen

e = Entry(l, show="*", width=30)
e.pack(side=TOP, anchor=W, padx=450, pady=300)
e.focus()

######################################################

# Fail entery

def make_entry(parent, caption, width=None, **options):
    tk.Label(parent, text=caption).pack(side=tk.TOP)
    entry = tk.Entry(parent, **options)
    if width:
        entry.config(width=width)
    entry.pack(side=tk.TOP, padx=10, fill=tk.BOTH)
    return entry

def enter(event):
    check_password()

def check_password(failures=[]):
    """ Collect 1's for every failure and quit program in case of failure_max failures """
    print(user.get(), password.get())
    if (user.get(), password.get()) in passwords:
        root.destroy()
        print('Logged in')
        return
    failures.append(1)
    if sum(failures) >= failure_max:
        root.destroy()
        raise SystemExit('Unauthorized login attempt')
    else:
        root.title('Try again. Attempt %i/%i' % (sum(failures)+1, failure_max))



#frame for window margin
parent = tk.Frame(root, padx=10, pady=10)
parent.pack(fill=tk.BOTH, expand=True)
#entrys with not shown text
user = make_entry(parent, "User name:", 16, show='')
password = make_entry(parent, "Password:", 16, show="*")
#button to attempt to login
b = tk.Button(parent, borderwidth=4, text="Login", width=10, pady=8, command=check_password)
b.pack(side=tk.BOTTOM)
password.bind('<Return>', enter)

user.focus_set()
###########################################################################

# Main Screen Shut Down

b = Button(l, command=quit, text="Shut Down")
b.pack(side=BOTTOM, expand=Y, anchor=S)


l.pack_propagate(0)
l.pack()


root.mainloop()

root = Tk()

# Modify root window

root.title("NEOSA Corp Interface")
root.geometry("1024x768")

# Kick off the event loop

root.mainloop()

There is no way to help someone who doesn't have a clue short of a Vulcan mind meld. But

e.focus()

there is no widget method "focus" [Click Here](http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm

and

if (user.get(), password.get()) in passwords:

we have no idea what is in "passwords" but if it is not a list or set of tuples, then it will not be found. I would suggest testing by printing passwords and then looking for user in all of the passwords[0] and password in all of the passwords[1] and print what is and is not found.

Finally, note that "failures" is set to an empty list every time the function is called so max_failures will never be reached

def check_password(failures=[]):

lists are mutable so you can define it outside of the function, and append to it in the function, unlike strings.

def check_password():
    failures.append(1)

failures=[]
for ctr in range(5):
    check_password()
    print failures
print sum(failures)

well basically what i'm mainly looking for is a entery with a password using a input box? so if i could disregard all that password stuff is there better way?

The simplest way is

import easygui
word = easygui.passwordbox()

You can then browse the easygui source code to learn how to make a passwordbox :) and remove the buttons if you want to.

commented: Could you send me a message? I have another question I got it to work now. +0

There is no problem with the entry boxes as the code below will show, i.e. name and password are printed correctly. The problem is verifying the input and "passwords" is not defined anywhere in the code you posted so we have no way to know what you are using to check the input against.

from tkinter import *

# Create the window
root = Tk()
root.title("NEOSA Corp Interface")

# Background
##p = PhotoImage(file="CIA.gif")  ## we don't have this image
l = Label(root)

# Password for main screen

e = Entry(l, show="*", width=30)
e.pack(side=TOP, anchor=W, padx=450, pady=300)
e.focus()

######################################################

# Fail entery

def make_entry(parent, caption, width=None, **options):
    Label(parent, text=caption).pack(side=TOP)
    entry = Entry(parent, **options)
    if width:
        entry.config(width=width)
    entry.pack(side=TOP, padx=10, fill=BOTH)
    return entry

def enter(event):
    check_password()

def check_password(failures=[]):
    """ Collect 1's for every failure and quit program in case of failure_max failures """
    print(user.get(), password.get())
    """
    *****  commented because we don't have "passwords"
    if (user.get(), password.get()) in passwords:
        root.destroy()
        print('Logged in')
        return
    failures.append(1)
    if sum(failures) >= failure_max:
        root.destroy()
        raise SystemExit('Unauthorized login attempt')
    else:
        root.title('Try again. Attempt %i/%i' % (sum(failures)+1, failure_max))
    """


#frame for window margin
parent = Frame(root, padx=10, pady=10)
parent.pack(fill=BOTH, expand=True)
#entrys with not shown text
user = make_entry(parent, "User name:", 16, show='')
password = make_entry(parent, "Password:", 16, show="*")
#button to attempt to login
b = Button(parent, borderwidth=4, text="Login", width=10,
           pady=8, command=check_password)
b.pack(side=BOTTOM)
password.bind('<Return>', enter)

user.focus_set()
###########################################################################

# Main Screen Shut Down

b = Button(l, command=quit, text="Shut Down")
b.pack(side=BOTTOM, expand=Y, anchor=S)


l.pack_propagate(0)
l.pack()


root.mainloop()

root = Tk()

# Modify root window

root.title("NEOSA Corp Interface")
root.geometry("1024x768")

# Kick off the event loop

root.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.