任何字符串都可以代表 turtle 中的 "backspace" 吗?
Can any string represent "backspace" in turtle?
import turtle as t
def erase():
if t.xcor() > -300:
t.goto(t.xcor()-5,t.ycor())
else:
prevline()
t.color("white")
t.begin_fill()
box()
t.end_fill()
t.color("black")
def prevline():
t.goto(300,t.ycor()+10)
t.Screen().onkey(erase,"_")
What would replace the "_" in the above code that would represent the backspace?
我相信 'BackSpace'
是您正在寻找的 tkinter keysym。
我会把你的示例代码写成这样:
from turtle import Screen, Turtle
def erase():
if turtle.xcor() > -300:
turtle.setx(turtle.xcor() - 5)
else:
prevline()
turtle.color('white')
turtle.begin_fill()
box()
turtle.end_fill()
turtle.color('black')
def prevline():
turtle.goto(300, turtle.ycor() + 10)
turtle = Turtle()
screen = Screen()
screen.onkey(erase, 'BackSpace')
screen.listen()
screen.mainloop()
虽然对角色进行白化很可能不尽如人意。我会考虑采用 undo()
或其他类似方法。
import turtle as t
def erase():
if t.xcor() > -300:
t.goto(t.xcor()-5,t.ycor())
else:
prevline()
t.color("white")
t.begin_fill()
box()
t.end_fill()
t.color("black")
def prevline():
t.goto(300,t.ycor()+10)
t.Screen().onkey(erase,"_")
What would replace the "_" in the above code that would represent the backspace?
我相信 'BackSpace'
是您正在寻找的 tkinter keysym。
我会把你的示例代码写成这样:
from turtle import Screen, Turtle
def erase():
if turtle.xcor() > -300:
turtle.setx(turtle.xcor() - 5)
else:
prevline()
turtle.color('white')
turtle.begin_fill()
box()
turtle.end_fill()
turtle.color('black')
def prevline():
turtle.goto(300, turtle.ycor() + 10)
turtle = Turtle()
screen = Screen()
screen.onkey(erase, 'BackSpace')
screen.listen()
screen.mainloop()
虽然对角色进行白化很可能不尽如人意。我会考虑采用 undo()
或其他类似方法。