admin管理员组文章数量:1122832
I've got a method of a class that is used to register the user, and has some tkinter entry with:
email=tk.StringVar()
nameent = tk.Entry(registerwindow,textvariable = email, font=('Arial',14,'normal'))
but when I try to get the value that has been inputted in the name entry it returns a blank result
I've tried getting it to output the entry value at multiple stages in the user registration process to see where it was erroring but I found that it doesn't even seem that it picks up the value from the entry from the beginning
I've got a method of a class that is used to register the user, and has some tkinter entry with:
email=tk.StringVar()
nameent = tk.Entry(registerwindow,textvariable = email, font=('Arial',14,'normal'))
but when I try to get the value that has been inputted in the name entry it returns a blank result
I've tried getting it to output the entry value at multiple stages in the user registration process to see where it was erroring but I found that it doesn't even seem that it picks up the value from the entry from the beginning
Share Improve this question edited Dec 21, 2024 at 17:25 toyota Supra 4,5338 gold badges21 silver badges24 bronze badges asked Nov 21, 2024 at 11:31 Charlotte WatsonCharlotte Watson 1 3 |1 Answer
Reset to default 0I assume that you want to use the user entered email. For instance, you may want to validate the email with a function or check whether email exists in the database. In that case, you don't need to declare a StringVar. By using nameent.get()
, you'll get the user entered email which you can use it in a function. For the sake of simplicity I've given my example without class which you can convert into class and function.
import tkinter as tk
def get_email():
email = nameent.get()
print(email)
root = tk.Tk()
root.geometry("300x200")
registerwindow= tk.Frame(root)
registerwindow.pack()
nameent = tk.Entry(registerwindow,font=('Arial',14,'normal'))
nameent.pack()
btn = tk.Button(registerwindow, text = "Get Email", command = get_email)
btn.pack()
root.mainloop()
本文标签: pythontkinter entry windows not working properly in oopStack Overflow
版权声明:本文标题:python - tkinter entry windows not working properly in oop - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736311355a1934708.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
Tk()
. – acw1668 Commented Nov 21, 2024 at 11:53email
is a local variable that is getting destroyed by the garbage collector. Without a proper minimal reproducible example it's impossible for us to say for sure. – Bryan Oakley Commented Nov 21, 2024 at 23:15