Skip to main content
  1. About
  2. For Teams
Asked
Viewed 106 times
0

When I run the following code, I receive the following error: NameError: name 'barE' is not defined.

Does Tkinter's Entry work from one function to another? I have a global window and frame in this program and it passes the user's input without error using the same syntax as below.

def newSearchForm():
    window2=Tk()
    window2.geometry("650x400")
    frame = Frame(window2)
    frame.pack(side="top", expand=True, fill="both")
    
    barcode=Label(frame,text="Please Enter The Barcode", font='time 15')
    barcode.place(x=10,y=90)
    barE=Entry(frame)
    barE.place(x=250,y=90)

    isbn=Label(frame,text="Please Enter The ISBN", font='time 15')
    isbn.place(x=10,y=130)
    isbE=Entry(frame)
    isbE.place(x=250,y=130)
    
    repeatSearchButton=Button(frame,text="Enter", command=newSearch,width=12,bg='gray')
    repeatSearchButton.place(x=150,y=170)
    
    window.mainloop()

def newSearch():
    uB = barE.get()
    uI = isbE.get()
    carlSearch(uB, uI)
    itemTitle=workspace.find_element_by_xpath('//*[@id="mainContent"]/div[2]/div[2]/div[2]/div[1]/div[1]/div').text
    ingramSearch()
    fantasticFictionSearch(itemTitle)
    outputMetadata()

I tried using the lambda command to explicitly pass the variables and that didn't work. I tried using anexising window and that didn't work, so I destroyed it and created a new one.

1 Answer 1

-1

I would suggest you to use text variable. You can create a text variable by StringVar and assign it in the entry widget.

For more details on why to use text variable see Should I use Entry's .get() or its textvariable's for Tkinter in Python?

Usage:

barE_var=StringVar()
barE=Entry(frame,textvariable=barE_var)
barE.place(x=250,y=90)

To get value use barE_var.get().

Does Tkinter's Entry work from one function to another?

It does work, but have to use global keyword to access them.

def newSearch():
    global barE_var
Sign up to request clarification or add additional context in comments.

3 Comments

"The Entry widget does'nt have any function named get. " - this is completely false. So is this: "To get value from Entry, you have to use text variable.".
@BryanOakley , thanks for the correction, i just got to know entry widget does have .get method. :)
@BryanOakley , would you like to help me regarding stackoverflow.com/questions/71546744/…

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.