Python-切换开关时如何清除屏幕
现在,当我使用tab键切换一个新算法时,我正试图使海龟图形屏幕清晰并重置所有内容。切换部分工作,但当切换到新算法时,我无法清除整个屏幕。Python-切换开关时如何清除屏幕,python,turtle-graphics,python-turtle,Python,Turtle Graphics,Python Turtle,现在,当我使用tab键切换一个新算法时,我正试图使海龟图形屏幕清晰并重置所有内容。切换部分工作,但当切换到新算法时,我无法清除整个屏幕。 我的代码如下所示: from pynput import keyboard from pynput.keyboard import Listener, Key, Controller import keyboard from turtle import Turtle, Screen, clearscreen, clear import sys def
我的代码如下所示:
from pynput import keyboard
from pynput.keyboard import Listener, Key, Controller
import keyboard
from turtle import Turtle, Screen, clearscreen, clear
import sys
def lefthand_Algo():
execfile('...')
def bfs_Algo():
execfile('...')
# Creates the title
def title():
t = Turtle()
t.color('white')
t.write('Hello, hit tab to start the algorithm!', font=('lemon',20,'normal'), align='center')
t.hideturtle()
screen = Screen()
clearscreen = clearscreen
clear = clear
screen.bgcolor("black") # Set the background colour
screen.setup(width=0.9, height=0.9) # Setup the dimensions of the working window
title = title()
current_state = bfs_Algo
next_state = lefthand_Algo
switch = False
def toggle():
global switch
switch = not switch
if switch:
next_state()
else:
current_state()
screen.onkeypress(toggle, "Tab")
screen.listen()
screen.mainloop()
注意:算法在单独的文件中,此文件仅用于在两个文件之间切换。
如何在每次切换时清除屏幕?非常感谢您的帮助!:) 来自评论中的@RhinoRunner: 使用
turtle.reset()
来自注释中的@RhinoRunner: 使用
turtle.reset()
你能提供完整的代码吗?你试过使用
turtle.reset
?@RhinoRunner哦,是的,成功了!我一直在想它要么清晰,要么清晰。谢谢:)@StackAsker7哈哈,我想clearscreen
是为pygame准备的!你能提供完整的代码吗?你试过使用turtle.reset
?@RhinoRunner哦,是的,成功了!我一直在想它要么清晰,要么清晰。谢谢:)@StackAsker7哈哈,我想clearscreen
是为pygame准备的!