简体   繁体   中英

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. but when I use get() I get empty space in the console.

在此处输入图像描述

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. 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")

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.

text = tk.StringVar()
recide = tk.Entry(root, width=50, textvariable=text)

You can access the variable with text.get()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM