Home > OS >  Extract text from Entry Box ktinker Python
Extract text from Entry Box ktinker Python

Time:12-30

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.

enter image description here

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:

enter image description here 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)

CodePudding user response:

As you have already implemented it above, you can get the input plane value using get() (recide.get()). Another method is to use the parameter textvariable as shown below. Where the value can be accessed again using get() (text.get()).

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

In my test case I could not reproduce this error. I modified their code slightly to output the value in the console as shown below.

import tkinter as tk

def test():
    str.set(recid.get())
    print(recid.get())

root = tk.Tk()

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 = test)
id_button.pack(pady = 5)

root.mainloop()
  • Related