pythonide清空_python idle怎么清屏?python清屏命令

class ClearWindow:

menudefs = [

('options', [None,

('Clear Shell Window', '<>'),

]),]

def __init__(self, editwin):

self.editwin = editwin

self.text = self.editwin.text

self.text.bind("<>", self.clear_window)

def clear_window2(self, event): # Alternative method

# work around the ModifiedUndoDelegator

text = self.text

text.mark_set("iomark2", "iomark")

text.mark_set("iomark", 1.0)

text.delete(1.0, "iomark2 linestart")

text.mark_set("iomark", "iomark2")

text.mark_unset("iomark2")

if self.text.compare('insert', '<', 'iomark'):

self.text.mark_set('insert', 'end-1c')

self.editwin.set_line_and_column()

def clear_window(self, event):

# remove undo delegator

undo = self.editwin.undo

self.editwin.per.removefilter(undo)

# clear the window, but preserve current command

self.text.delete(1.0, "iomark linestart")

if self.text.compare('insert', '<', 'iomark'):

self.text.mark_set('insert', 'end-1c')

self.editwin.set_line_and_column()

# restore undo delegator

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个简单的 Python 贪吃蛇代码: ```python import turtle import time import random delay = 0.1 # 设置幕 wn = turtle.Screen() wn.title("贪吃蛇游戏") wn.bgcolor("green") wn.setup(width=600, height=600) wn.tracer(0) # 创建蛇头 head = turtle.Turtle() head.speed(0) head.shape("square") head.color("black") head.penup() head.goto(0, 0) head.direction = "stop" # 创建食物 food = turtle.Turtle() food.speed(0) food.shape("circle") food.color("red") food.penup() food.goto(0, 100) # 创建身体列表 segments = [] # 创建分数 score = 0 high_score = 0 pen = turtle.Turtle() pen.speed(0) pen.shape("square") pen.color("white") pen.penup() pen.hideturtle() pen.goto(0, 260) pen.write("分数: 0 最高分: 0", align="center", font=("Courier", 24, "normal")) # 移动函数 def go_up(): if head.direction != "down": head.direction = "up" def go_down(): if head.direction != "up": head.direction = "down" def go_left(): if head.direction != "right": head.direction = "left" def go_right(): if head.direction != "left": head.direction = "right" def move(): if head.direction == "up": y = head.ycor() head.sety(y + 20) if head.direction == "down": y = head.ycor() head.sety(y - 20) if head.direction == "left": x = head.xcor() head.setx(x - 20) if head.direction == "right": x = head.xcor() head.setx(x + 20) # 设置键盘绑定 wn.listen() wn.onkeypress(go_up, "Up") wn.onkeypress(go_down, "Down") wn.onkeypress(go_left, "Left") wn.onkeypress(go_right, "Right") # 循环游戏 while True: wn.update() # 检查是否碰到边界 if head.xcor()>290 or head.xcor()<-290 or head.ycor()>290 or head.ycor()<-290: time.sleep(1) head.goto(0,0) head.direction = "stop" # 隐藏身体 for segment in segments: segment.goto(1000, 1000) # 身体列表 segments.clear() # 重置分数 score = 0 # 重置延迟 delay = 0.1 pen.clear() pen.write("分数: {} 最高分: {}".format(score, high_score), align="center", font=("Courier", 24, "normal")) # 检查是否吃到食物 if head.distance(food) < 20: # 移动食物到随机位置 x = random.randint(-290, 290) y = random.randint(-290, 290) food.goto(x, y) # 添加新的身体 new_segment = turtle.Turtle() new_segment.speed(0) new_segment.shape("square") new_segment.color("grey") new_segment.penup() segments.append(new_segment) # 缩短延迟 delay -= 0.001 # 增加分数 score += 10 if score > high_score: high_score = score pen.clear() pen.write("分数: {} 最高分: {}".format(score, high_score), align="center", font=("Courier", 24, "normal")) # 移动身体 for index in range(len(segments)-1, 0, -1): x = segments[index-1].xcor() y = segments[index-1].ycor() segments[index].goto(x, y) if len(segments) > 0: x = head.xcor() y = head.ycor() segments[0].goto(x, y) move() # 检查是否碰到身体 for segment in segments: if segment.distance(head) < 20: time.sleep(1) head.goto(0,0) head.direction = "stop" # 隐藏身体 for segment in segments: segment.goto(1000, 1000) # 身体列表 segments.clear() # 重置分数 score = 0 # 重置延迟 delay = 0.1 pen.clear() pen.write("分数: {} 最高分: {}".format(score, high_score), align="center", font=("Courier", 24, "normal")) time.sleep(delay) wn.mainloop() ``` 你可以将代码保存为 `snake.py` 文件并在命令行中运行。注意需要先安装 turtle 库。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值