[英]Extract text from Entry Box ktinker Python
I have a tkinter project and need the text, I put it in the Entry box, printed it in the console.我有一个 tkinter 项目,需要文本,我把它放在输入框中,在控制台打印出来。 but when I use get() I get empty space in the console.
但是当我使用 get() 时,我在控制台中得到了空白空间。
this is my interface.这是我的界面。 when I put 1234 I could place it above when I click the button "Pull record data" but I need that number in my console.
当我放置 1234 时,我可以在单击“拉取记录数据”按钮时将其放置在上方,但我需要在控制台中使用该数字。 to use that entry for other things.
将该条目用于其他事情。 but when I try to print it I get nothing in the console like this:
但是当我尝试打印它时,我在控制台中什么也得不到,如下所示:
root = tk.Tk() root.geometry("390x500") root.title("Airtable Project Tracker")
root = tk.Tk() root.geometry("390x500") root.title("Airtable 项目跟踪器")
str = tk.StringVar(root)
str.set('ie. recveGd8w9ukxLkk9')
tk.Label(root, textvariable=str).pack()
recid = tk.Entry(root, width=50)
recid.pack(pady = 10)
print(recid.get())
id_button = tk.Button(root, text="Pull record data", width=50, command = lambda:str.set(recid.get()))
id_button.pack(pady = 5)
recide
is an obejckt, if you create it you can pass the parameter textvariable
to acces the value. recide
是一个 obejckt,如果你创建它,你可以传递参数textvariable
来访问值。
text = tk.StringVar()
recide = tk.Entry(root, width=50, textvariable=text)
You can access the variable with text.get()
您可以使用
text.get()
访问变量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.