私は、ユーザーがウィンドウをクリックすると、選択した入力に基づいて図形を描画するようにコードを作成しています。私はどこにウィンドウとカメを正しく割り当てるべきか、そして現在のウィンドウを終了する方法を関数に割り当てる方法に問題があります。 mainloop()
を終了する方法はありますか?そのため、ユーザーは選択した数のシェイプをクリックして作成した後にメインメニューに戻ります(オプションを選択するたびにウィンドウが空白にリセットされる)。無制限のクリックが不可能な場合は、それを行う方法はありますか?クリックは1回だけです(メインメニューに戻ります)。簡単にするために、私は他のコードが同じであるため、1つのオプションしか含めませんでした。ユーザーがメインメニューに戻るようにPythonのカメの描画を終了
import turtle
window = turtle.Screen()
turt = turtle.Turtle()
def U(x,y):
turt.penup()
turt.setposition(x,y)
turt.pendown()
for x in range(4):
turt.forward(100)
turt.right(90)
return
def main():
global choice
if choice.upper() == "U":
window.onscreenclick(U)
window.mainloop()
run = True
print("Please choose a drawing option: 'U' or 'q' to quit.")
while run == True:
choice = str(input())
if choice.upper() != "U" and choice.lower() != "q":
print("Invalid input. Please choose either: 'U' or 'q'.")
elif choice.upper() == "U":
main()
elif choice.lower() == 'q':
run = False