[Solved] Turtle gives WARNING: Secure coding is not enabled for restorable state and doesn't print – Python

by
Ali Hasan
llama-cpp-python macos nssecurecoding turtle-graphics

Quick Fix: To fix this issue, modify the order of your code. Before calling screen.exitonclick(), print screen. print("Hi") then call screen.exitonclick().

The Problem:

When running a Python script using the turtle module to create a graphical turtle window and move the turtle, the program fails to print a message ("Hi") as expected. Instead, it generates a warning message: "WARNING: Secure coding is not enabled for restorable state and doesn’t print." How can this issue be resolved to display the message?

The Solutions:

Solution 1: Reordering Code Execution

The issue arises because the code exits immediately after calling screen.exitonclick(). To ensure the output ("Hi") is printed, the code should be reordered:

from turtle import Turtle, Screen

timmy_the_turtle = Turtle()
timmy_the_turtle.shape("turtle")

# Print "Hi" before exiting
print("Hi")

# Create and exit the screen
screen = Screen()
screen.exitonclick()

In this way, the output is printed before the program exits.

Solution 2: Move the print statement

The provided code works as expected, but to see the "Hi" message printed in the console, you need to move the print("Hi") statement before the screen.exitonclick(). This is because the program ends before the print statement can execute.

Here’s the updated code:

from turtle import Turtle, Screen

timmy_the_turtle = Turtle()

timmy_the_turtle.shape("turtle")

print("Hi")  # Move the print statement here

screen = Screen()
screen.exitonclick()

With this modification, you should see the message "Hi" printed in the console when you run the program.

Q&A

What does WARNING: Secure coding is not enabled for restorable state! mean?

This message is related to macOS-specific functionality and doesn’t affect your code.

Why is "Hi" not being printed?

The program exits before printing ‘Hi’ due to the order of your code. Reorder the code to fix this.

Video Explanation:

The following video, titled "How to Fix Webcam Issues in Windows 10 - Camera Not Working ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

... WARNING: If the steps in this tutorial are not performed correctly, it could damage your computer. Perform the steps in this tutorial at ...