简体   繁体   English

如何从 python 的输入框中获取文本?

[英]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.

相关问题 如何从文本框中获取条目。 蟒蛇 - How to get entry from Text Box. Python 如何制作交互式 tkinter 文本框,然后是输入框,然后是文本框作为对输入的响应 - How do I make an interactive tkinter text box, then entry box, then text box as a response to the entry 在python中,如何从Gtk.entry输入框中获取值并将其传递给变量? - In python, how can I get a value from a Gtk.entry entry box and pass it to a variable? 如何从输入框中获取值并将其插入文本框中 - How to get a value from an entry box and insert it in a text box 在 SQLite 中,如何使用输入框中的文本搜索我的数据库,并将结果显示为文本? - In SQLite, how do I search my database with text from an entry box, and display the result as text? 从输入框中获取文本并插入到电子邮件python中 - get text from entry box and insert in email python 如何从我的输入框中获取信息以供稍后在 Python 程序中使用? - How do I get information out of my entry box to use later in my program in Python? Python、Tkinter - 如何从条目中获取文本 - Python, Tkinter - How to get text from Entry 如何从Tkinter文本框中获取选定的字符串? - How do I get a selected string in from a Tkinter text box? 如何使用tkinter for python中的迭代创建输入字段和按钮以从输入字段获取内容? - how do I create entry fields and buttons to get the content from the entry field using iteration in tkinter for python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM