How to use Python tkSimpleDialog.askstring
python, tkinter, user-input
Solution
tkSimpleDialog.askstring returns `None` if the user clicks Cancel or closes the window (instead of clicking Ok or using the Enter key); you should check for that (what do you want to do if the user chooses to cancel? surely not call `urlopen` anyway...).
Apart from that, you're using the function correctly; I imagine that by "has no value" you mean `is None`, right?
Problem
I want to use the response from an askstring prompt to set a variable. Unfortunately, I have the dilemma that I'm trapped in the loop asking the question or the window refuses to draw because the variable (urltoopen) has no value. The code as it stands: ``` urltoopen = tkSimpleDialog.askstring('Address', 'Where do we get the pictures from?') usock = urllib2.urlopen(urltoopen) data = usock.read() usock.close() ```