Getting PY_VAR1 when i print 'query'

2020-05-05 01:26发布

问题:

Im making a simple web srape code and when i try to print a value it gives me something else.

def PeopleSearch():
query = SearchTerm
query = ('what is '+ query)
print str(query)


SearchTerm = StringVar(None)
SearchText = Entry(app, textvariable=SearchTerm)
SearchText.pack()

'SearchTerm' is gotten from a text Box. If i try to print str(query) i get PY_VAR1. And i get PY_VAR1 no matter what i type.

But this only happens when i do it from program containing tkinter module. Without GUI, it prints exactly what i typed in.

What is up? Huh?

回答1:

StringVar is an object which manages the value - to get the value itself you want SearchTerm.get()