无法使用条目小部件

时间:2020-08-09 16:20:52

标签: python python-3.x tkinter tkinter-entry

我正在用python创建登录系统

但是有一个问题

def createAccount():
root1 = Tk()
root1.resizable(0, 0)
root1.title('Signup')
instruction = Label(root1, text='Please Enter new Credentials')
instruction.grid(row=0, column=0, sticky=E)

nameL = Label(root1, text='New Username: ')
pwordL = Label(root1, text='New Password: ')
nameL.grid(row=1, column=0, sticky=W)
pwordL.grid(row=2, column=0, sticky=W)

nameE = Entry(root1)
pwordE = Entry(root1, )
nameE.grid(row=1, column=1)
pwordE.grid(row=2, column=1)

signupButton = Button(root1, text='Signup')
signupButton.grid(columnspan=2, sticky=W)
root1.mainloop()
username = nameE.get()
password = pwordE.get()
with open('user_accounts.json', 'r+') as user_accounts:
    users = json.load(user_accounts)
    if username in users.keys():
        top = Toplevel()
        top.title("Error")
        top.geometry('310x64')
        top.resizable(0, 0)
        text = Text(top)
        text.insert(INSERT, "This username is already in use. ")
        text.configure(state='normal')

        text.configure(state='disabled')

        text.pack()
        btn2 = Button(top, text="Close This Window", command=top.destroy).place(x=100, y=40)

    else:
            users[username] = [password, "PLAYER"]
            user_accounts.seek(0)
            json.dump(users, user_accounts)
            user_accounts.truncate()
            top = Toplevel()
            top.title("Account created!")
            top.geometry('310x64')
            top.resizable(0, 0)
            text = Text(top)
            text.insert(INSERT, "The account is created. Now Login. ")
            text.configure(state='normal')

            text.configure(state='disabled')

            text.pack()
            btn2 = Button(top, text="Close This Window", command=top.destroy).place(x=100, y=40)

在这种情况下,我会收到这样的错误

**

回溯(最近通话最近): 在“ 调用”中的文件“ /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/init.py”,行1705 返回self.func(* args) 在createAccount中,文件“ /Users/mananvyas/PycharmProjects/pythonProject/login.py的最新尝试”,第27行 用户名= nameE.get() 在get中的文件“ /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/init.py”,行2682 返回self.tk.call(self._w,'get') _tkinter.TclError:无效的命令名称“。!entry”

**

有什么解决办法吗?

预先感谢

0 个答案:

没有答案