[英]How do I get the text from an entry box in python?
I tried creating a login system.我尝试创建一个登录系统。 it gives me a: 'NoneType' object has no attribute 'get'它给了我一个:'NoneType' object 没有属性'get'
here is the code:这是代码:
import tkinter
from tkinter import ttk
window = tkinter.Tk()
def addUsernm():
a = usernl.get("1.0", 'end-1c')
print(a)
usernames = []
passwords = []
usernl = tkinter.Entry(window).pack()
passwrdnl = tkinter.Entry(window).pack()
submitbtn = tkinter.Button(window,text="submit",command=addUsernm).pack()
window.mainloop()
How do I fix this?我该如何解决?
The issue is, you're confusing the Text widget get() method, with the Entry widget get() method, and they aren't the same method.问题是,您将 Text 小部件 get() 方法与 Entry 小部件 get() 方法混淆了,它们不是同一个方法。 Also you can't use pack() on the same line as widget or the variable won't be saving anything.此外,您不能在与小部件相同的行上使用 pack(),否则变量将不会保存任何内容。 This is the solution that worked for me:这是对我有用的解决方案:
from tkinter import * window = Tk() window.state("zoomed") def add(): a = user.get() b = password.get() print(a,b) user = Entry(window) user.pack() password = Entry(window) password.pack() submitbtn = Button(window,text="submit",command=add).pack() window.mainloop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.