1

问题是我有一个作为函数创建的测验的登录窗口,但是每当我调用该函数时,代码都会继续进入测验,然后我才能在登录中输入任何信息。

这会导致错误: Traceback(最近一次调用最后一次):文件“C:\Users\Thoma\Documents\PrPg\2021 nea 2.py”,第 368 行,在 if loginfo[0] == '1': TypeError: “NoneType”对象不可下标

我的主体是:

loginfo = login()
print('test')

print(loginfo) #NOTE - BROKEN HERE AS IDK HOW TO STOP THE CODE FROM CONTINUING
if loginfo[0] == '1':
    subject = input('History, Music, Computer Science: ')
    difficulty = input('Easy, Medium, Hard: ')
    score = questions(subject, difficulty)

[从这里截断,因为其余的不是必需的]

登录窗口功能是:


def login():
    
    def getdetails():
            details = getname(),getage(),getyear()
            print(details)
            file = open('login.txt','r')
            for line in file:
                
                info = line.split(",")
                username = info[0]
                password = info[1]
                yeargroup = info[2]  
                print(username)
                if details[0] == username and details[1] == password and details[2] == yeargroup:#Checks if the user input is on the information file and allows the user to log in

                    loggedin = 1
                    #creates the a label
                    Label(root, text=('hello',info[0]), bg = '#00FFFF', font=('Comic Sans MS', 32, 'normal')).place(x=365, y=139)
                    Button(root, text='Close', bg='#ff0000', font=('Comic Sans MS', 32, 'normal'), command=lambda:root.destroy()).place(x=304, y=429)
                    print(' Here ')
                    #reads the information on th user and displays it to them
                    return(loggedin,username)
                
            else:
                    Label(root, text='invalid data has been inputted. Check your details and try again', bg='#ff0000', font=('Comic Sans MS', 12, 'bold')).place(x=180, y=190)


    # this is a function to get the user input from the text input box
    def getname():
            nameInput = entername.get()
            return nameInput


    # this is a function to get the user input from the text input box
    def getage():
            ageInput = enterage.get()
            return ageInput


    # this is a function to get the user input from the text input box
    def getyear():
            yearInput = enteryear.get()
            return yearInput

  
    


    root = Tk()
    
    # This is the section of code which creates the main window
    root.geometry('876x572')
    root.configure(background='#00FFFF')
    root.title('Login')


    # This is the section of code which creates a text input box
    entername=Entry(root)
    entername.place(x=354, y=231)


    # This is the section of code which creates a text input box
    enterage=Entry(root)
    enterage.place(x=354, y=258)


    # This is the section of code which creates a text input box
    enteryear=Entry(root)
    enteryear.place(x=354, y=285)


    # This is the section of code which creates the a label
    Label(root, text='Login', bg='#00FFFF', font=('arial', 32, 'normal')).place(x=365, y=139)


    # This is the section of code which creates the a label
    Label(root, text='name', bg='#00FFFF', font=('arial', 12, 'normal')).place(x=300, y=231)


    # This is the section of code which creates the a label
    Label(root, text='age', bg='#00FFFF', font=('arial', 12, 'normal')).place(x=315, y=260)


    # This is the section of code which creates the a label
    Label(root, text='year', bg='#00FFFF', font=('arial', 12, 'normal')).place(x=310, y=283)


    # This is the section of code which creates a button
    Button(root, text='Continue', bg='#00FFFF', font=('arial', 32, 'normal'), command=(lambda:getdetails())).place(x=294, y=329)
    
4

0 回答 0