我是蟒蛇和乌龟的初学者。我想制作一个询问是或否的问题的对话框。虽然我可以弹出这个盒子,但是我怎么编码它以便“no”关闭龟程序而“是”会保持它? screen.textinput下方的部分是错误的,但我之前已经有了终端,我在上面导入了龟。
screen = turtle.getscreen()
screen.textinput("Welcome to Bowling!", "Are you readt to bowl?!")
if start.lower() == 'yes':
print("Start!")
else:
print("Goodbye!")
turtle.clear
turtle.bye()
这应该让你开始:
import turtle
screen = turtle.Screen()
answer = screen.textinput("Welcome to Bowling!", "Are you ready to bowl?")
if answer is None or answer.lower().startswith('n'):
print("Goodbye!")
screen.clear()
screen.bye()
else:
print("Start!")
要记住的关键是textinput()
返回用户键入的字符串,如果用户点击取消,则返回None
。