How to use Python tkSimpleDialog.askstring
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?
root = Tk() try: urltoopen = tkSimpleDialog.askstring('Ask Address', 'Where do we get the pictures from?') usock = urllib2.urlopen(urltoopen) data = usock.read() usock.close() a = data except: sys.exit()
works fine. But it does need error handling (as mentioned by Alex).