I'm a beginner in programming and have encountered an issue with my code. I even tried to use AI, but it's code didn't work at all. Here is my code:
from keyboard import is_pressed as isp
import keyboard
import turtle
t = turtle.Turtle()
t.speed(10)
r_ang = 10
is_writing=True
def is_wr(is_writing):
is_writing = not is_writing
def on_f_key_event(e):
if e.event_type == keyboard.KEY_DOWN:
is_wr(is_writing)
keyboard.hook_key('f', on_f_key_event)
while True:
if isp('w'):
t.forward(2)
if isp('a'):
t.left(r_ang)
if isp('d'):
t.right(r_ang)
if is_writing:
t.pendown()
if is_writing==False:
t.penup()
The program should allow you to control the drawing turtle with the wad keys and switch writing mode to the f key. Drawing already works, but switching the writing mode doesn't. Every time I try to fix something, the program either fails to perform the action or gives a lot of errors that I don't understand. My problem is that I can't register the f key press to enable and disable drawing for the turtle. *This version of the code does not generate errors, but it does not perform the function either. Thanks in advance for your reply.