Python 文本框

Python text box

我正在尝试从用户那里获取输入的姓名、电子邮件和密码,并将其打印在屏幕上。但是每次使用的变量都显示 none 。谁能解决我的问题?

import tkinter as tk
import tkinter.font as f


r = tk.Tk()
name=''
email=''
password=''

def Print():
   print("Name is",name)
   print("Email is",email)
   print("Password is",password)


f=tk.Frame(r,height=600,width=900)
f.pack()


name = tk.Label(f, text = "Name").place(x = 30,y = 50)  

email = tk.Label(f, text = "Email").place(x = 30, y = 90)  

password = tk.Label(f, text = "Password").place(x = 30, y = 130)  

sbmitbtn = tk.Button(f, text = "Submit",activebackground = "pink", activeforeground = "blue",command=lambda:[Print(),f.destroy()]).place(x = 30, y = 170)  

e1 = tk.Entry(f,textvariable=name).place(x = 80, y = 50)  
e2 = tk.Entry(f,textvariable=email).place(x = 80, y = 90)  
e3 = tk.Entry(f,textvariable=password).place(x = 95, y = 130)  

r.mainloop()  

您可以使用StringVar 来获取字符串。 Label 中的 textvariable 需要是 Tkinter 变量,引用: "

textvariable= Associates a Tkinter variable (usually a StringVar) to the contents of the entry field. (textVariable/Variable)

你可以阅读更多here

import tkinter as tk
import tkinter.font as f

r = tk.Tk()
name = tk.StringVar()
email = tk.StringVar()
password = tk.StringVar()


def Print():
    print("Name is", name.get())
    print("Email is", email.get())
    print("Password is", password.get())


f = tk.Frame(r, height=600, width=900)
f.pack()

tk.Label(f, text="Name").place(x=30, y=50)

tk.Label(f, text="Email").place(x=30, y=90)

tk.Label(f, text="Password").place(x=30, y=130)

sbmitbtn = tk.Button(f, text="Submit", activebackground="pink", activeforeground="blue",
                     command=lambda: [Print(), f.destroy()]).place(x=30, y=170)

e1 = tk.Entry(f, textvariable=name).place(x=80, y=50)
e2 = tk.Entry(f, textvariable=email).place(x=80, y=90)
e3 = tk.Entry(f, textvariable=password).place(x=95, y=130)

r.mainloop()