Anonymous User 123
Anonymous User 123

Reputation: 3

TypeError: descriptor 'readlines' of 'file' object needs argument

I'm trying to make a Tkinter Login Gui but if I click Log in it the displays the message "TypeError: descriptor 'readlines' of 'file' object needs argument" I tried looking for an answer and most of them were because of case-sensitive errors. Could someone please help me out. I've set up the profile.txt file properly(I'm 100% sure)

def LogIn():
    name=input("Please enter your name: ")
    file = open(name.lower() + "profile.txt", "r")
import Tkinter
import time
window = Tkinter.Tk()
window.title("Python Games Login")
window.geometry("270x210")
window.configure(bg="#39d972")

def callback():
    line = file.readlines()
    username = user.get()
    password = passw.get()
    if username == line[1] and password == line[2]:
            message.configure(text = "Logged in.")
    else:
        message.configure(text = "Username and password don't match the      account \n under the name;\n \'" + name + "\'. \nPlease try again.")

title1 = Tkinter.Label(window, text="--Log in to play the Python Games--  \n",   bg="#39d972")
usertitle = Tkinter.Label(window, text="---Username---", bg="#39d972")
passtitle = Tkinter.Label(window, text="---Password---", bg="#39d972")
message = Tkinter.Label(window, bg="#39d972")
user = Tkinter.Entry(window)
passw = Tkinter.Entry(window, show='*')
go = Tkinter.Button(window, text="Log in!", command = callback, bg="#93ff00")
title1.pack()
usertitle.pack()
user.pack()
passtitle.pack()
passw.pack()
go.pack()
message.pack()
window.mainloop()

Upvotes: 0

Views: 1897

Answers (1)

beezz
beezz

Reputation: 2428

Your problem is that you are assigning to file in function and it's not propagated to the globals thus in function callback it's not what you are expecting.

file it's (as hinted in comments) builtin python type therefore you receive this kind of error and not NameError as it would be for undefined variable.

Please check for example this question to get better understanding how variable scopes work in python.

Upvotes: 2

Related Questions