import sys
import time
from random import randint
replies =["It is certain", "It is decidedly so", "Without a doubt", "Yes definitely", "You may rely on it", "As I see it, yes", "Most likely", "Outlook good", "Yes", "Signs point to yes", "Reply hazy try again", "Ask again later", "Better not tell you now", "Cannot predict now", "Concentrate and ask again", "Don't count on it", "My reply is no", "My sources say no", "Outlook not so good", "Very doubtful"]
def question():
print "What is your question?"
question = raw_input()
print "Thinking"
time.sleep(3)
print replies[randint(0,19)]
end()
def end():
print "Thanks for playing! Do you want to try again?"
user_reply = raw_input()
if user_reply == "Yes" or "yes":
question()
else user_reply == "No" or "no":
print "Goodbye!"
sys.exit
print
print "**********Welcome to the Magic 8-ball!**********"
print
question()
虽然很好,但我想做一些更具挑战性的事情。我想添加一个GUI(Tkinter)来使它更有趣。我应该从哪里开始?
答案 0 :(得分:0)
在这种特定情况下,最好的解决方案是从头开始重写程序。 GUI程序不像您的程序那样自上而下地工作,GUI程序不应该调用sleep
。您需要从事件驱动的角度重新思考程序应该如何工作。