url=StringVar()
txt1=Entry(root,textvariable=url)
txt1.pack()
button1 = Button(root, text="Download" ,command=downloadFile)
button1.pack()
root.mainloop()
好的,这是我的基本 GUI...我有一个文本框 txt1,我想在下面的函数中使用它
def downloadFile():
#print "url is:",url
file_name = url.split('/')[-1]
我的目标是在文本框中输入 URL,然后在我的函数 downloadfile() 中拆分 URL,但我的 url 变量变为 PY_VAR0 而不是“www.example.com/file.exe”
我得到的错误消息是“StringVar 实例没有属性拆分”我做错了,但我不知道在哪里。有人可以帮忙吗?