Reputation: 912
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?
Upvotes: 0
Views: 1320
Reputation: 6226
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]
Upvotes: 2