0
url=StringVar()
txt1=Entry(root,textvariable=url)
txt1.pack()

button1 = Button(root, text="Download" ,command=downloadFile)
button1.pack()
root.mainloop()

ok this is my basic GUI... I have a textbox txt1 which i want to use in the function below

def downloadFile():
    #print "url is:",url
    file_name = url.split('/')[-1]

My aim is to feed in the URL in the textbox and then split the URL in my function downloadfile(), but my url variable becomes PY_VAR0 instead of "www.example.com/file.exe"

and the error message I get is "StringVar instance has no attribute split" I am doing something very wrong but i don't know where. Can anyone help please?

1 Answer 1

2

StringVar is just a "Value holder for strings variables". To get its content (the string) use:

StringVar.get() # Return value of variable as string.

printing the StringVar directly ("print url") invokes:

StringVar.__str__() # Return the name of the variable in Tcl.

which will return the internal variable name, not its value. in your code use:

file_name = url.get().split('/')[-1]
Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

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.