[Tutor] moving focus away from a raw_input dialog box
keridee at jayco.net
Fri Oct 22 02:57:10 CEST 2004
I'm not exactly sure of the code conditions you have, but I might be
able to help.
Instead of making 0 the exit of the whole while loop, set up a while 1 loop.
Then you can set up if, elif, else commands to search for different commands
received from the raw_input box.
ask = raw_input("What is your hair color? ")
if ask == "quit" or ask == "exit":
break ## This breaks out of the while loop
elif ask == 'green':
print "Wow! I don't know anyone with green hair!"
elif ask == 'blonde' or ask == 'blond': ## Since people spell it
differently, check for both spellings
print "Your hair color is the same as mine."
print "Your hair color is obviously not important enough to make
it in my program."
You can make one of the commands 'print list of commands' to print out
possible entries for ask or something like that.
Many of my programs are structured like that. It is probably frowned on by
the more professional programmers, though.
Hope this helps,
More information about the Tutor